A PivotTable is an interactive table that summarizes data to present it in a meaningful way. You can rotate a PivotTable's rows and columns to see different summaries of the source data, or drill down to show details. By displaying different views of data, PivotTable reports allow you to easily compare data, see patterns and relationships, and analyze trends.
Without OfficeWriter, SQL Server Reporting Services cannot export a report to Excel format while maintaining a PivotTable. Report users have to to manually set up PivotTables every time they they export a PivotTable report from Reporting Services to Excel.
With OfficeWriter, you design your PivotTable only once at report design-time. Each time you run the report, OfficeWriter will export the report to Excel and plug the data into the PivotTable. In this section we will explore using PivotTables in a report created with OfficeWriter Designer.
This query returns company purchase data from the AdventureWorks database, sorted by Vendor ID and Employee ID. This is the data that will be used in this report.
Below is a screenshot of an Excel template with data markers that will be populated with the data from the above query.
After running the report, the imported data looks like this:
Creating a PivotTable
- On a sheet, different than the sheet with the data markers, select the cell where you would like to insert the pivot table.
- Go to Insert > PivotTable on the Excel ribbon
- When prompted to select data, navigate to the sheet with the data markers. Select the header row and the data marker row. Click OK when finished.
- This will insert a blank PivotTable into the second worksheet.
- Drag VendorName into the Row Labels section and EmployeeID into the Column Labels section. Drag TotalDue into the Values section.
- In the Excel ribbon, go to Design and select a style to apply to the PivotTable.
You've added a PivotTable to your report, but there are a few settings that need to be changed before we're done.
Field Settings and PivotTable Options
- You will note that the formula used to aggregate the TotalDue field is currently set to Count. This is because the only data in the data source is a data marker, which is a string. Right click the TotalDue field and select Value Field Settings.
- Switch the summarize formula to be Sum instead of Count. Click OK when finished.
- Right click on the PivotTable go select PivotTable Options
- Go to the Data tab.
- To make sure that the new imported data is pulled into the PivotTable when you open the rendered report, you have to set the PivotTable to Refresh data when opening the file.
If you don't do this, your PivotTable will look exactly the same as it does in the template until the PivotTable is refreshed.
- Under the Retain items deleted from the data source you will see a Number of items to retain per field drop-down. Select None from the dropdown.
If you don't, the data markers that are currently in your data source will be carried over to the output file. The data markers will appear in the PivotTable label filters.
- Click OK when finished.
You are now done setting up the PivotTable in your report template.
Viewing the PivotTable
Notice that on the first sheet, your data columns display the correct data.
Now look at the sheet containing your PivotTable. You should find the EmployeeID numbers across the top and all the vendor names along the left column. Each cell will contain the sum for each vendor/employee combination.
Click on the down arrow next to the Vendor Name label. Clear Show All and just select a few vendors.
Do the same for the EmployeeID field.
Now look at your results.
Viewing the Report in Reporting Services Report Manager
In your browser, type the path to the Report Manager (Usually http://<YourReportServer>/Reports). Navigate to the report and view it.
To see the report as you designed it with OfficeWriter:
- From the export option drop-down list, choose Excel designed by Officewriter.
- You will be prompted to save or open the output file. If your report contains a PivotTable AND you are using Internet Explorer 8 or earlier, you MUST select Save. After it saves to disk, then you may select Open to view it.
This is because of an issue with how Internet Explorer caches temporary internet files. If you are using any other browser or Internet Explorer 9 or later, this issue does not occur and you can open the file directly.