SSRS subreport
In this SSRS tutorial I will show you how tocreate subreport in SSRS. I will use SSRS 2008 R2 but this tutorial should also work in SSRS 2008 and SSRS 2012.
Just to clarifyasubreport is a report which we want to display (embed)in main report.
First picture shows a report with sparkline which takes one parameter @date. In this tutorial I will use this report and emded it into main report.
Make sure that you have Dataset, Data Source and Parameter setup already.
In our example we will create a dataset called TrendWeeks which actually will contain only 1 row! We will use it to force a table to display a one cell we will add our subreport.
NOTE: Normally you would use real life dataset and display a subreport once or multiple times (many rows)with different parameters.
Our subreport takes one parameter "date" and in our main report we will create the same parameter "date" and pass it to the subreport.
NOTE: Very often you will pass either parameters to a subreportwhich is presentedin this tutorialor you will pass values from a field which we will try to cover in a separate SSRS tutorial.
If you would like to know more about parameters please read our article "how to create parameter in ssrs" (link coming soon)
To add table please open Toolbox and drag and drop table into design area.
Using your dataset insert the columns you need inthe table. In my case I will only add header.
In "Data" cellI will add subreport. You can either use right click option (see below) or use toolbox.
Once sub report is added go to Sub report Properties.
In Subreport Properties we need to type Name and select sub report from drop down box.
NOTE: In drop down box you should onlysee reports that are part of your solution.
In the next step I will set up parameters.
To do this I click "Parameters" on the right side and click Add button.
A row will appear where I can select subreport parameters and option to pass value.
NOTE: SSRS in 2008 R2 has a bug. If you select subreport and go to parameters you will see in drop down box all parameters from subreports BUT if you close the properties box and go again without selecting subreport you will get EMPTY drop down box. To "fix" it you need to go to General section select subreport AGAIN which actually does something, go to Parameters section and try the drop down box. This time you should see parameters from subreport in the drop down box.
Now that we select parameter name from subreport from Name drop down box I need to pass value and in my case I want to pass value from my main report parameter called DATE which allows users to select a date using a calendar. To do that I click the expression button (fx)... (Ignore the OK button on the screenshot below it shouldn't be there)
In Set expression for: Value box I can use my parameters by typing =Parameters!Date.Value
alternatively in category section I can select Parameters and double click my data parameter.
Click ok
Now when my parameter is setup I click okbutton
NOTE: A shortcut for parameter name in value box is [@ParameterName] see below our [@Date]
We can now preview our report and see a subreport that uses a date from the parameter.