SSRS Calculate between subreports - reporting-services

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.

Related

SSRS Report - using the value from the subreport in a calculation in my main report

I am writing an SSRS report using report builder and have my main report and a sub report - I have had to do this because one of the figures is in a different table. The main report shows a customer column an amount column then my subreport column - in the next column I need to show these two figures added together, there is then a further column with another figure in and the final column will deduct the fourth from the calculated third - I dont know how to write an expression which incorporates the subreport value.
You can't retrieve values from a subreport like you wish as that's not how subreports work.
When you run the SSRS report, the parent report passes parameters to the sub-report (the only data transfer between the two), the subreport is rendered and then the rendered subreport is inserted back into the parent report as the parent report is rendered.
As I see it, you have two options to tackle the problem.
1) Join the data from the two tables in your source query so that all the appropriate information is within one dataset in your report.
2) Use the Lookup function to retrieve values from the second dataset. This is a very flexible option and one that I highly recommend that you review for scenarios like this.

Access - Modular reusable subreport

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...

Get data from a subreport into the main report

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.

Report structure from table

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)

SSRS IIF Syntax with Multiple Datasets

I have a report with 2 data sets and would like to perform a SUM operation in a textbox expression. The problem arises when I want to perform an IIF in the sum since I only want a particular category of values summed.
I would like to get a sum of all the "Good" ranking values from the dsRetrieveCustomerAssetScores dataset. Please note there is more than one data set in the report, so I need to specify the scope when using the aggregate function. Below is the code I've tried (along with other permutations).
=Sum(iif(Fields!ranking.Value,"Good",1,0), "dsRetrieveCustomerAssetScores")
Any ideas?
You may have more than one dataset in your report, but I don't think it's possible to have more than one dataset per tablix. (Subreports within the tablix may be bound to a different dataset, but anywhere within the subreport will only be accessing that other dataset.)
The scope specified within aggregation formulas is normally related to groups within the tablix, not the datasources.
So, the code:
=Sum(iif(Fields!ranking.Value,"Good",1,0))
- should work within your tablix, as long as that tablix is accessing the dsRetrieveCustomerAssetScores dataset.