I have made one main report containing a few subreports. At the end I would like to compare some figures from the different parts of the report and also make some calculations with numbers received from the different parts.
Does anybody know a way to get values from the subreport into the main report? All calculations e.g. aggregates that will be made at the end refer only to the dataset for the main part and the other subreports have their own datasets, fetched from other tables.
I must second #JoaoLeal's comment, I think the method you propose (retrieving data from a subreport in the main report) is technically not possible.
However, there's another way to achieve what you want (show aggregate info on the data displayed in subreports). You could encapsulate your dataset queries in a way that they can be reused by the main report. There are two main/basic options:
Use a stored procedure to query the data
Use a database view for the data
Your datasets will be very simple: the subreports will select all the data. The main report can then either have a dataset query that aggregates data appropriately from the view / proc, or also retrieve all results and do the aggregation in SSRS.
I think in RDLC report there is no way for share variable between main report and subreport . So the only way is use another dataset or passing new vaiable. Hope this will help...
I have myself managed to achieve what I expected through using different datasets on the main form which also contains data for the sub reports.
But also I found this way (not tested):
[Reports]![YourReportName]![YourSubReportName]![TheValueFromTheSubReportYouWantToReference]
There is also a long discution about this on SQL Server Central.
Related
I have a customer dataset from a main report which I bind to a list. In this list I have a subreport. How do I pass the each row of data to the subreport? I don't want to pass an id from main report to subreport then call a stored procedure to fetch the record based on the id. I already have all the details flattened out in the dataset which i fetched from the main report.
The fact is that you can't pass a set of rows as a parameter to a subreport. The most common approach is to have a shared dataset so you can execute it again based on the same parameters or a store procedure for exactly the same purpose. Only other thing can be done, and it's to convert a dataset's field into a string containing all the values, and then split it again. This is done with SSRS built-in functions join and split (if I'm not wrong), but to be honest I don't know if that solves your problem and it's a really nightmare to get it working properly.
My standard approach is to have efficient stored procedures that can be executed any times within a set of SSRS reports. I understand that you want to retrieve each datataset only once, but SSRS is not meant to make that easy.
And even more important, if you queries or procedures are efficient, data retrieval time is just a tiny porting of all SSRS report build and presentation time. Usually rendering the report is what takes longer and some repeated data extraction won't be noticed in the overall execution.
If you what to be really efficient in data retrieving, you can explore the options provided to cache data in datasets, but stills seems to be too complex to solve something that doesn't really need a solution.
Hope this helps.
I would like to create a report which I can use as a sub-report multiple times on the same parent report. However, each occurrence of the subreport should have different values.
For instance, there is a table called DailyReport.
Records in this table contain:
Date, member, team, description
The sub reports should be for each team within a certain date range. However, the date range per subreport/team will not be the same.
So, if the date range for all teams was consistent, then I could create a single subreport, and do some Ordering on the resulting records to separate things out into teams.
However, with inconsistent date ranges, I can't utilize a single query, so the most straight forward solution I see is to create separate subreports and queries for each range of each team.
The problem with this solution is that if I decide to change the format of the subreports I must do so in each specific subreport--a lot of duplicate work.
I would like to create a generic query and subreport. The query and sub report would call VB functions which would return the relevant value.
This means my parent report has the same generic report on it multiple times. As each subreport is rendered, I would like to increment a value behind the scenes so that the functions which the generic query and subreport call know to return a different value.
However, it seems that's not how things work in Access. The subreports on a report are not rendered linearly. A subreport is created, and then "stamped" onto a report where ever required. This means that all of my generic subreports have the same data.
How can I define a generic report and query? Then plug in different values into the report and query while the report is being reused multiple times on the same parent report.
You need to look into the LinkMasterFields and LinkChildFields property of reports. They are designed for exactly this purpose -- to filter a subreport based on current data in the main report, without needing any code or even queries.
You are correct that LMF/LCF do not work on date ranges, only values. So use LMF/LCF for the team filter.
For the date range filtering, you can use an unbound form that launches the report as two parameters defined in the base query. Create frmLaunch, and add two text boxes minDate and maxDate. Set their Format property to Short Date so Access with interpret them correctly and provide the date pickers. Now modify the base query, adding two Date/Time parameters [Forms]![frmLaunch]![minDate] and [Forms]![frmLaunch]![maxDate]. Now, find your date field and set its criterion to Between [Forms]![frmLaunch]![minDate] and [Forms]![frmLaunch]![maxDate]. Add a button to frmLaunch that runs the code DoCmd.OpenReport "YourReportName", acViewPreview.
So, the goal was to make it possible to re-use the same sub-report multiple times on the same parent report, with full flexibility on how the subreport retrieves data.
I placed multiple instances of the same subreport on a parent report. On the subreports Open event I placed a line like
Me.Report.RecordSource = "SELECT * FROM someTable WHERE " & getCriteria()
nextCriteria()
Maybe its possible to pass a value that identifies which instance of the subreport is opening to the getCriteria function. Probably like a getCriteria(Me.Report.Name). But in this case I kept track of how many subreports had been produced in vb.
Unfortunately, if your subreport has controls which have a data source which is a vb function, all reports will show the same value for that control. To get around this I added something like getSomeValue() & "As [Some Value]" into the SELECT of the SQL statement above. Don't forget to add single quotes or hashes around getSomeValue() if you are passing a String or date.
That's basically it, it's a pain. But I couldn't find a more elegant way to do it.
Edit:
One major caveat I experience with doing this, is that although the print preview works correctly, when actually printing or exporting to PDF, some subreports would not be included. Maybe there is something else causing this...
I am trying work on a requirement using SSRS 2008 R2. The requirement is to create a detailed report which has main query(dataset1). And a column in this main query is used as a join or input to another query(dataset2).
I am trying to create a parameter and get the value for this from the main query or dataset1. How do I assign this parameter to dataset2? Also I will have similar situation to create dataset3, dataset4 etc and all this sub queries needs to be joined to dataset1.
Can you please help me what is the best way to do this?
In Dataset2, use a SQL variable in your query. SSRS will create a report parameter for you. Then go into this new report parameter and tell it that its available values should come from Dataset1.
Then repeat for the other datasets. :)
I've got an SSRS report, where the data is such that the only way I have been able to figure out how to get the report correctly populated is using subreports. That piece works fine, but what I need to do is have another field where I compute the difference between subreports. So, basically I need an expression that does Subreport1.value - Subreport2.value. Is that even possible?
Why don't you just take the datasets populated from each one and put it in the main report? I don't think SSRS can see the objects inside of a subreport to my knowledge. You would need to put one or many values into different tables, matrices, or text boxes for each dataset as you cannot mix datasets in a single object. Then you could take the column values and do aggregates on those. EG: ReportItems!(nameoftextbox).value - ReportItems!(nameofothertextbox).value.
I have a large project with a lot of reports, but the items in the reports are quite standard, reusable with parameters. So I've made subreports, that's OK. Now I assemble the reports by adding subreports to them by hand, plus setting the parameters, also by hand.
I think that this is not flexible enough, I'd like to have a table that defines the structure of the report: like one row per subreport, specifying the name and its parameter values. Then the report would be assembled together runtime in a list or something like that, by calling and inserting the subreport by name.
Is it possible somehow?
I can't think of a way to dynamically assemble a report like that without coding something that would generate the required RDL, upload it to the report server and then execute the report.
Another option might be to create one master report with all possible subreports in it. You could then use a table to control the visibility of each subreport, to simulate generating different reports. Obviously you don't want to execute long running queries for subreports that are hidden, so you would have to add a parameter to all your subreports so that if the subreport is hidden the dataset returns no data, e.g.
WHERE
(....) OR (#SubReportHidden = 'Hidden' AND 1=0)