A Subreport is a report item that displays another report inside the body of a main report. It is basically used to embed a report within a report. Any report can be used as a Subreport. We can pass the parameter into Subreport from Main report. We can place a Subreport in the main body of the report, or in a data region. If you place a Subreport in a data region, the Subreport will repeat with each instance of the group or row in the data region.
Here we are going to create report and its sub report based on Accounts and Contacts data:
- MainReport: It will show Accounts data.
- Sub Report: It will show Contacts related to a specific Account based on input parameter from MainReport.
We can also achieve this through grouping but with a disadvantage:
When we apply a grouping, the Contacts related to an Account will be shown in the next row after the Account. But, using Subreports we can see the Contacts related to an Account in the same row.
Step 1: Create a new report which is Mainreport with Account details.
Step 2: Below is the dataset used for the MainReport.
Step 3: Create another report which is Subreport with Contact details.
Step 4: Below is the dataset used for the Subreport.
Step 5: Automatically based on query provided in Subreport a new Parameter will be created. Here in this example based on above screenshot “ACCOUNTID” is a Parameter that will be created automatically. (Instead of GUID we have to provide Parameter Name for the value in the Query).
Step 6: Save and Build the Subreport.
Step 7: For embedding “Contacts” report as Subreport in Mainreport (Accounts), go to Mainreport, right click on the Contact Text Box à Insert à Subreport:
Step 8: Right click on the Subreport region and select Subreport Properties.
Step 9: Select the report that need to embed into the Mainreport:
Step 10: Under Parameters section add the Parameter that we created in the Subreport.
Step 11: Save and Build the Report.
Shows the Contacts of the specific Account: