Tuesday, June 30, 2015

SSRS - Main Report with Sub-Reports

In this article, we will learn that how to call a sub report into main report. There are very easy steps which should need to follow.


What is a Sub-Report?
I would like to introduce a Sub-report as a simple report item which will display in inside the body of a main report.  It will use as embedded Item within a report and any report can be used as a Sub-report. A sub report mostly takes the parameter from main report. We can place a Sub-report in a data region, the Sub-report will repeat with each instance of the group or row in the data region. We can add more than one sub report into the main report.

We have already created a parameterised “Employees Details Report” and you can also create that report by clicking here. We will use that report as the Sub-report in this article.

Before creating a main report with sub report in Reporting Services, we need to know about the output of the SSRS report. We are assuming that we have Employee Master Data table in our database which contains the following information –

1) Emp Id
2) Name
3) Age
4) Salary
5) Department

EmpId
EmpName
EmpSalary
EmpAge
Department
105
Eliza Roy
 $  15,965.00
25
Admin
112
Roy Chauhan
 $  15,965.00
25
Admin
108
Rahul Kuamr
 $  15,965.00
22
Finance
101
Anil Sharma
 $  15,965.00
22
Finance
102
Bill Smith
 $  18,540.00
25
HR
109
Gary White
 $  18,540.00
25
HR
100
Amit Gupta
 $  15,450.00
32
IT
107
Sumit Singh
 $  15,000.00
32
IT
113
Lucky God
 $  15,965.00
23
Others
106
Flash God
 $  15,965.00
23
Others
104
David King
 $  18,025.00
22
Procurement
111
King Street
 $  18,025.00
22
Procurement
103
Chris Gray
 $  18,025.00
28
Sales & Marketing
110
Rosy Wang
 $  18,025.00
28
Sales & Marketing

We need to display this information in our SSRS report and Report header should be like as “Department Wise Employees Summary”. In this report, we will show the department name and number of employees in the each department. Every department will show the employees details in the data region which will be called the Subreport.


Subreport Screen:


Main report Screen without Subreport:


Subreport within Main Report.



We need to follow the following steps to implement our first Subreport into main SSRS Report:

1) On the start window, All Programs list chose SQL Server Data tools from Microsoft SQL Server 2012.


2) SQL Server Data Tools will open as –


3) Now, Click File, Add, New Project (ctrl+shift+N) from the top-level menu –


4) Chose a Report Server project to the solution. Fill in the Add New Project dialog as shown below:  


At this point, we have created a Report Server project called “Reports” as shown above.

5) Click OK button on the New Project window and will Launch the report wizard-


6) In the Solution Explorer, Right Click on the Shared Data Sources and click on Add New Data Source.


7) Then Shared Data Source Properties window will open. Change the name as DataSource and click on the Edit Button.


8) Click the Edit button to display the Connection Properties dialog; fill in your Server name and select the respective database which contains the data for the report as shown below:


9) Click on the Test Connect button to verify the connection is working or not for the report as shown below –


10) After connection verification, click OK Button.
11) Window will return to Shared Data Source Properties window as shown below-


12) Click OK button to finish the Shared Data Sources wizard, now we have the DataSource to get the information from the database as shown below:


13) Right click on the reports folder, choose Add and click on New Item as shown below:


14) This will open Add New Item – Reports, choose Report and named as Department Wise Employee Summary as shown below:




15) After click on Add button, SSDT will create Department Wise Employee Summary report. We need to add report header to the report as shown below :



16) Here is now; we need to open Report Data. In the Report Data, Right click on the Datasets and click on the Add dataset as shown below:


17) Add Dataset will launch Dataset properties window. We need to set the name as DeptEmployeeSummary for the Dataset and choose a dataset embedded in my report and choose Query Type Text as shown below:


SELECT 
                EmpId,
                EmpName,
                EmpSalary,
                EmpAge,
                Department
FROM
                dbo.Employees
Order by
                Department




18) After click on the OK button, a dataset has been added in the report data as shown below:


19) Now right click on the report and add table as shown below:


20) Add dataset to the table as shown below:


21) Now right click on the report details and Add Group to choose Parent Group to the repots as shown below:




22) It will launch the Tablix group, we need to select Department as Group by and checked Add group header as shown below:


23) Now we have the following data into the report as shown below:


24) Click Preview on the report as shown below-


Now, we need to remove details row as shown below:


Now, we need to remove extra columns from the report as shown below:


We need to add total number of the employees in the each department as shown below:



25) Now, we need to insert a new row inside the group as shown below:


26) After adding the blank row inside the group, we need to right click on the new blank row and choose merge cells as shown below:


27) We need to right click on the blank row and choose Subreport from the insert options as shown below:


28) Right click again on the added Subreport and click on Subreport Properties as shown below:


29) In the Subreport Properties window, choose the Subreport as shown below:


30) In Subreport Properties window, we need to set the Parameters to the Subreport as shown below:


31) Click on OK button and we have added the Subreport in the main report as shown below:



32) Click on the preview and view the report as shown below:


This completes the tutorial section of the Sub-report implementation into the main report. You can watch this tutorial demo at

For the Drilldown report, you can click here.
If you want to create the Drillthrough report then you can click here.

Monday, June 29, 2015

SSRS - Drill-through Report

A drill-through reports is the combination of the two reports. One report is known as the base or main report having link option to call another report and second report is known as the sub report in this scenario which must have the parametrized functionality because drill through reports commonly contain details about an item that is contained in an original summary (main) report.

We have already created a parametrized report and you can also create that report by clicking here and use that report as the sub report in drill through SSRS report – 

Note: A sub report can act as the main report as well as a main report can act as the sub report. These reports act as vice versa with each others.

Before creating a drill through SSRS report, we need to know about the output of the SSRS report. We are assuming that we have an Employee Master Data table in our database which contains the following information –

1) Emp Id
2) Name
3) Age
4) Salary
5) Department

EmpId
EmpName
EmpSalary
EmpAge
Department
105
Eliza Roy
 $  15,965.00
25
Admin
112
Roy Chauhan
 $  15,965.00
25
Admin
108
Rahul Kuamr
 $  15,965.00
22
Finance
101
Anil Sharma
 $  15,965.00
22
Finance
102
Bill Smith
 $  18,540.00
25
HR
109
Gary White
 $  18,540.00
25
HR
100
Amit Gupta
 $  15,450.00
32
IT
107
Sumit Singh
 $  15,000.00
32
IT
113
Lucky God
 $  15,965.00
23
Others
106
Flash God
 $  15,965.00
23
Others
104
David King
 $  18,025.00
22
Procurement
111
King Street
 $  18,025.00
22
Procurement
103
Chris Gray
 $  18,025.00
28
Sales & Marketing
110
Rosy Wang
 $  18,025.00
28
Sales & Marketing

We need to display this information in our SSRS report and Report header should be like as “Department Wise Employees Summary”. In this report, we will show the department name and number of employees in the each department. Whenever user clicks on the department link button then it will drill through the report and shows the employees details in that department as shown below:
For the report, we need to add a report filter to display the data only for the selected employee department.
We need to follow the following steps to create our first SSRS Drill Through Report:
1) On the start window, from the all Programs list choose SQL Server Data tools from Microsoft SQL Server 2012.

2) After choosing the SQL Server Data tools, SQL Server Data Tools will open as –


3) Now, Click File, Add, New Project (ctrl+shift+N) from the top-level menu –


4) Chose a Report Server project to the solution. Fill in the Add New Project dialog as shown below:  
At this point, we have created a Report Server project called “Reports” as shown above.
5) Click OK button on the New Project window and will Launch the report wizard-
6) In the Solution Explorer, Right Click on the Shared Data Sources and click on Add New Data Source.

7) Then Shared Data Source Properties window will open. Change the name as DataSource and click on the Edit Button as given below:
8) Click the Edit button to display the Connection Properties dialog; fill in your Server name and select the respective database which contains the data for the report as shown below:

9) Click on the Test Connect button to verify the connection is working or not for the report as shown below –

10) After connection verification, click OK Button.


11) Window will return to Shared Data Source Properties window, Click OK Button to close the shared data source properties window.
12) Click OK button to finish the Shared Data Sources wizard, now we have the DataSource to get the information from the database as shown below:


13) Right click on the reports folder, choose Add and click on New Item as shown below:


14) This will open Add New Item – Reports, choose Report and named as Department Wise Employee Summary as shown below:


15) After click on Add button, SSDT will create Department Wise Employee Summary report. We need to add report header to the report as shown below :


16) Here is now; we need to open Report Data. In the Report Data, Right click on the Datasets and click on the Add dataset as shown below:


17) Add Dataset will launch Dataset properties window. We need to set the name as DeptEmployeeSummary for the Dataset and choose a dataset embedded in my report and choose Query Type Text as shown below:

SELECT   EmpId,
                EmpName,
                EmpSalary,
                EmpAge,
                Department
FROM
                dbo.Employees
Order by
                Department


18) After click on the OK button, a dataset has been added in the report data as shown below:


19) Now right click on the report and add table as shown below:


20) Add dataset to the table as shown below:


21) Now right click on the report details and Add Group to choose Parent Group to the repots as shown below:


22) It will launch the Tablix group, we need to select Department as Group by and checked Add group header as shown below:


23) Now we have the following data into the report as shown below:
  

24) Click Preview on the report as shown below-


Now, we need to remove details row as shown below:

Now, we need to remove extra columns from the report as shown below:


We need to add total number of the employees in the each department as shown below:


After down the all the formatting to the report, click on the preview and report will look like as shown below:


25) Now we need to add drill-through functionality to the report. Right click on the Department group Text box click on the Text Box Properties as shown below:


26) In Text Box Properties, set the action as Go to the Report. Specify a report name and add the report parameter for the specified report  as shown below-

27) Click OK button and do the needful formatting to the link for Department as shown below:
28) Now, we are ready to preview of the report as shown below:

Click on the department link, it will show the following report –
This completes the tutorial section of the simple drill-through report.
For the Drilldown report, you can click here

Popular Posts