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

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.

Related

Can you link multiple tablixes on a key field in a single SSRS report?

I am creating a report in SSRS to show evaluation scores. It has three sections, and I need to link them all together on the PreceptorID field (2108 in this case). The top two sections are from the same query. I am filtering the results in each one to separate the counts because they have different column names. The third section is a subreport showing comments from evaluators. It also has the PreceptorID field in the data but is not displaying it. It has two parameters that should be populated by the main report query, but that does not appear to be happening. The report is returning all comments instead of only the ones with the matching PreceptorID.
This first image is from Crystal Reports showing how the finished product should look.
This is what I am getting from SSRS. It is showing counts for multiple people at the top. The counts in the middle are actually correct. They are all for the one person. The next person's counts are on the next page. The comments at the bottom are also not filtering on the one PreceptorID.
This image showing the subreport parameter that should be linking it back to the main query.
How can I tell all three sections to only return data for the same person on one page, and another person on the next page?
I would redesign the report structure slightly. This is only my personal preference, there are several ways to achieve this but I find this way easier to manage and maintain.
You'll need two subreports and a master report.
You already have the 2nd subreport so no extra work required there.
I would take you current report, strip out the link to the current subreport and change it so it only processes a single person (just like your existing sub report).
So SubReport1 will have the two tables from your current main report only. It will only accept a single person as a parameter (or pair of parameters in your case)
SubReport2 will be your current subreport. Again it only accepts a single person.
Next create a new report. This will be the master report.
Add a dataset that contains just enough info for list of people you want to report over. So the dataset query might be as simple as
SELECT PreceptorID, ClerkshipID FROM myTable ORDER BY PreceptorID
Add a table to this report and set it's dataset property to the dataset you just created.
Change the default (details) row group to group and order by whatever makes each record unique (maybe both the two columns listed above, may only one will be required, only you will know this).
Right-Click on the row header to the left of your table and do "Insert Row => Inside Group Below".
Remove all but one column
You should now have a table with 2 rows per group.
Right click the top cell in the group and do "Insert => Subreport", go to the subreport properties and point this to SubReport1 (or whatever you called it) and set the parameters has you have done previously.
Repeat this for second row, this time pointing to your second subreport.
In the row group properties, set page breaks to "Between each instance"
That should be it. This was done from memory so might not be 100% but based on the info in your question you should be able to work it out from here.
Things to check if this is not working
Open each subreport and test it by passing in parameters manually. Each subreport should only be returning data for a single person.
The master report should have a dataset that returns each person once i.e. if there are 10 people in total this dataset should only contain 10 rows.
The table in the master report should contain only two rows
Both rows must be EITHER within the same row group, or, if you have no other row groups, they will both be in the detail row group.
The report design should look something like this if you have a row group by person
or like this if you only have detail rows.
Finally, make sure the parameters you pass to your subreports are the Field values from your master report's dataset, NOT your master reports parameters.

SSRS Create As Many Tables As Needed (Using One Dataset) Based on a DataSet Field

I have a query that returns relevant data about inspectors and how long it takes them to respond to issues. The only parameters are a BeginDate and EndDate so for any given date range there could be anywhere from 0 to 100 inspectors.
I am using only one dataset and it contains an "Inspector" field that I'm hoping can be used as a filter to create as many tables as there are inspectors.
I know you can set filters on tables but from my (limited) SSRS knowledge, you must already have the tables created and the filters are typically hard-coded. What I need, is some way for the report to see how many Inspectors there are in the dataset and group those records into their own tables, repeating the same one created tablix over and over as needed.
This is being done strictly in SSRS 2012, not using a ReportViewer where back-end code could help me out unfortunately...
I don't have any code examples to provide, like I said I know you can do filtering but I am at a loss when it comes to doing something like this dynamically based on data... Sorry.
Depending on the report design you could either...
Single report with grouping
1. Create a single tablix.
2. Create a row group by Inspector and then add whatever fields you need to the details section.
3. You can optionally set page breaks between instances of your Inspector rowgroup from the rowgroup properties.
Sub report method
1. Create a subreport that accepts a parameter (InspectorID for example).
2. In the subreport filter the dataset using the parameter passed in so it only return data for a single inspector.
3. Add whatever controls you need to the report to handle a single Inspector
4. Create a main report
5. Add a dataset that gives you a simple distinct list of Inspectors, this will be used to pass parameters to the subreport.
Lets assume it just contains a list of InspectorIDs.
6. Add a list control to the report and set it's dataset property to the dataset that contains your list of InspectorIDs
7. Right-click in the list control's 'cell' and insert a subreport.
8. Set the subreport property to the subreport you created earlier and set that parmameter IsnpectorID to your InpsectorID field.
This will produce a subreport for each instance of inspector it finds.
Sorry about the format of this answer, in a rush!

How to populate an rdl table based on data returned from a query?

I have absolutely no experience working with rdl files and I received a ticket from a client asking us to display multiple reports in one report. What I have done so far is created a master rdl file that contains a sub-report. That subreport is linked to another rdl file which is the actual report that is normally generated. What I want to do is generate a list of those subreports based on the data received in an array from a query. So if there are 6 elements in the array then I need to have 6 subreports generated, with each report using data from the appropriate index in the array.
I managed to figure out how to connect the data for one subreport but I have no idea how to scale that programatically.
The basic steps are
Create a subreport that accepts parameters (done I guess)
Create a master report (done)
Create a dataset in your master report that contains a row of data for each subreport. For example. If you subreport showed employee details for a single employee, your main report might contain a dataset that lists employee IDs for a department.
Add a tablix to your main report, remove header row and leave only a single column. Stretch this column to fit your report width
Set the datasetname property of the tablix to the name of your dataset, (now it will produce one row per employee)
Right click the tablix cell and insert subreport
Right click the subreport placeholder -> properties then choose your subreport form the drop down.
Set the subreport parameter(s) to be the values from your dataset (e.g. EmployeeID = empID)
That's it.
You main report will run, the tablix will create a row per record in your dataset, this in turn will give you a subreport per row in your dataset, each of those subreports will have the value of the field from that row passed to it.
If you need more help, I'll try to track down a similar answer I posted a while back which had more detail.

SSRS 2008 R2 Subreport Displays Only on First Page

Long time browser of this site, but first time poster. Normally I'm able to find the answer I need by searching, but in this case I haven't been able to, and it's driving me nuts!
I'm using BIDS / SSRS 2008 R2 to create a membership renewal form which my business will mail out to our customers. The form contains customer information, including membership dues / subscription info and other billing details.
In order to accomplish this,
I have built three RDLs:
Main report (this is one the users run). Contains base data set
(let's call it Proc 1), which requires an expiration date only, to
pull a list of member IDs and corresponding physical information
(address, phone, membership type, etc.) Contains the first subreport,
in a list, grouped by member ID.
One subreport for the first page in the main report. Contains a
set of parameters for each field it needs. Rather than execute Proc 1
again, I pass Proc 1's output from the main report to this subreport.
Everything in this subreport is also contained within a list, grouped
by member ID parameter (passed from main report).
Another subreport, nested within the first subreport, which pulls
subscription information. First subreport passes member ID and paid
through date to detail data set in nested subreport (let's call it
Proc 2). Proc 2 requires paid through date from page one subreport,
and ONE member ID, which it gets from its parent report. It displays
this information in a table, not grouped, since it should only be
receiving one ID at a time--- being that its parent subreport. and the
main report. are already grouped. However, I have tried grouping the
table based on member ID, and it didn't make a difference.
I found this approach necessary, because of the fact that I had two write two separate stored procs: one to pull the basic data, and one to pull detailed billing data. It's impossible to combine the two without creating duplicate rows. And of course, it's not possible to have a tablix assigned to a different data set than the list it is contained within. Hence the need for a subreport. I hope that all makes sense.
Anyway, my issue is that the nested subreport only displays data for the first customer. In fact, it doesn't display the nested subreport AT ALL for the rest of the customers. It's as if the nested subreport is only being passed the first member ID, but I don't see how that's possible given the grouping? Note that I am not using any FIRST or aggregate functions in the proc or report expressions. And I can execute each report file just fine individually.
I have tried creating a dummy data set in the nested subreport (ex. SELECT 'Nothing' AS Nothing) and adding it to a text box, thinking that this would force the nested subreport to display, but it STILL doesn't. Thoughts on what I might be doing wrong? Thanks in advance.
https://social.msdn.microsoft.com/Forums/en-US/9f8b9c42-90cb-4620-ad91-9754029ed4db/seemingly-random-error-subreport-could-not-be-shown-in-a-report-with-nested-subreports-ssrs?forum=sqlreportingservices
Your nested subreport could be throwing an error that your not seeing.
Quote
The known issue in SQL Server 2008 Reporting Services described in http://support.microsoft.com/kb/967749 should be fixed in SQL Server 2008 R2. Generally, the issue occurs because the parameter value is not passed to the subreport correctly or the subreport is not valid due to the specific values passed to the subreport.
I think you should add a detail group then put the subreport in that cell. Make sure the grouping is working correctly and pass the right values to the subreport.

SSRS Calculate between subreports

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.