|
How to Create Excel Reports
> Working with PivotTables
Working with PivotTables
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.
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. 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.
The following example uses the AdventureWorks2000 sample database
that ships with Reporting Services. It is assumed that you already know
how to set up a report in Excel using OfficeWriter Designer. If you do
not know how to do this, see
Create Your First Excel Report.
Step 1. Add Data Markers to Your Workbook

- Open Microsoft Excel and create a new workbook.
- Click Add Query on the OfficeWriter toolbar.
- Follow steps 2-11 of
Create a Database Query in
Create Your First Excel Report.
- In the Add Tables dialog box, find the PurchaseOrderHeader table in the
list and select Add. Click Close.
- In Microsoft Query, drag the following fields to the query:
EmployeeID, TotalDue, and VendorID.

- Add the Vendor table and its Name field
to the query. Make sure the VendorID field from the PurchaseOrderHeader table
is connected to the VendorID field from the Vendor table.

- From the File menu, select Return to OfficeWriter
Designer.
- Add the fields - as data markers -
and a header row to your report, as shown.

- Publish the report.
- Click View on the OfficeWriter toolbar to see the
populated report.
- Click Close Report View to return to the report template.
Step 2. Create a PivotTable

- With your mouse, highlight both the header row and the row
containing your fields.
- Open Excel's Data menu and select
PivotTable and Pivot Chart Report to open the PivotTable
Wizard.
- Select Microsoft Office Excel list or database from the
top section and PivotTable from the bottom
section and click Next.
- Since you highlighted the header and field rows of your report,
the Step 2 screen should already contain the cell
range to use. Click Next.
- Select New Worksheet and click Finish. You should
now have an empty PivotTable in your worksheet, as shown.

- Click the Vendor Name field from the field list box and drag it to
where it says Drop Row Fields Here.
- Click and drag the Employee ID field to where it says
Drop Column Fields Here.
- Click and drag Total to where it says Drop Data Items Here.
Your PivotTable should look like this:

- By default, this will give us a count of rows for each vendor/employee
combination. However, for our example, we want a sum of the totals for each
vendor/employee. So, on the PivotTable where it says Count of Total,
right-click and select Field Settings. Under Summarize by, change
Count to Sum and click Ok. Your PivotTable should now look
like this:

Data Placeholders

When the report is executed, the data markers that you created in
Step 1 will be replaced with values from the
database. To ensure that the PivotTable is constructed properly, you
must replace the data markers with placeholder data - any data that
will be of the same format as the real output data. For example, if the field
is numeric, such as our EmployeeID field, we may use a zero or any other
number. If the field is a character field, such as the Name field, we need to
use a character placeholder. For our example, we will use the word 'none' for
Name and a zero for EmployeeID.
- Under the Vendor Name label, replace '=%%Query1.Name'
with 'none.'
- Under the Employee ID label, replace
'=%%Query1.EmployeeID' with '0'.
| When you insert placeholder data, never use a
real value. For example, if you are displaying a city name, don't use 'Boston' for
the placeholder data. The results returned for 'Boston', in that case, may not
behave as expected. The same holds true for numeric data. Try to find a value that
will never actually be in the query's result set. |
Refreshing the Data

There is one more thing to do before trying our PivotTable. Right-click on the
PivotTable and select Table Options. Near the bottom
of the left column, make sure Refresh on Open is checked. If you do not
check this, when the report is viewed, your PivotTable will be empty.

Viewing the PivotTable

Publish, and View
your report. 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 Select a format drop-down list, choose
Excel (.xls) designed by Officewriter.
- Click Export.
- You will be prompted to save or open. If your report contains a chart
or a PivotTable, you MUST select Save. After it saves to disk,
then you may select Open to view it.

Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.
|