XLPivotTableIntro06 07
XLPivotTableIntro06 07
Paula Ecklund
The Fuqua School of Business
Duke University
Summer 2006
CONTENTS
A Row Field
A Column Field
A Data Field
Data Plus Row Only or Data Plus Column Only
Drag and Drop
Inner Row or Inner Column Fields
The Pivot Table Page Field
Microsoft introduced Pivot Tables into Excel with Excel version 5. Pivot Tables replaced Excel’s
older cross-tabulation feature. A Pivot Table displays the data contained in a column of an Excel
list (database) by means of subtotals (or other calculations) that are defined by another column
in the same list. The other calculations might be averages, counts, percentages, standard
deviations, and so on.
Below is a simple example that shows how putting data in a Pivot Table can be useful.
The illustration at left above is a view of a simple list, or Excel database. Even looking at this
short list it’s difficult to discern patterns in the data. For example, it takes a bit of study to see
that the number of Units Sold in the Northeast region is much greater than the number of Units
Sold for the Southwest region or to find out that Gouda outsells Brie in the Northwest.
Questions like this can certainly be answered, but only with some effort.
By contrast, the Pivot Table in the illustration at the above right simplifies and summarizes the
data to make relationships and patterns obvious. And, if you had much more data in the list
(perhaps with many additional entries for each region), a condensed Pivot Table summary the
same size as the one at right could still be achieved.
1
The Pivot Table allows the inclusion or exclusion of any part of the list data. For example, I’ve
excluded the year information in the sample Pivot Table above. I could easily add it back in.
To chart the data in the list pictured at left above you’d first need to restructure the data and
obtain the sum for each region. The Pivot Table simplifies preparing the data for charting
because it obtains subtotals automatically. Excel’s Pivot Table also includes a Pivot Chart
feature and the Pivot chart can be selected during the automated creation process or at any
point afterward.
160
40
20
0
Northeast Northw est Southeast Southw est
a data field, where the data field is the variable you want to summarize. (There
can be more than one data field. A data field is usually numeric data although it
can be non-numeric.)
a row and/or column field where the row and/or column fields are the variables
that will “control” the data summary
2
Creating a simple Pivot Table: Step-by-Step
3
If you didn’t make a list cell the current cell then this is the step in which you identify
the Pivot Table data. A range reference (like the one shown above) or a range name can
be used here.
4
To draft a first version of the Pivot Table, drag items from the field list onto areas of the
Pivot Table structure. For example, the very simple Pivot Table illustrated below uses
Client Name as the Pivot Table row field and Total Sales as the Pivot Table data field.
The default Pivot Table operation on data is a sum. As simple as this Pivot Table is, it
summarizes by client name all the “Total Sales” values in the data. For example, at left is
a partial view of the source data. Records for the City of Morton are shown. The Pivot
Table with Client Name in the row field and Total Sales in the data field automatically
sums all sales values by client.
5
More about the Pivot Table
A Row Field
A row field in a Pivot Table is a variable that takes on different values. For example, a
row field might be “Manufacturer” and its values might be “Schwinn”, “Cannondale”,
and “Omega”.
In the example below, for each value of the variable “Manufacturer”, the Pivot Table
displays a summary of the chosen data field in an adjoining column. The data field in
this example is “Annual Sales” and the summary function is sum.
Notice that the Pivot Table uses the label “Sum of Annual Sales” to identify not only the
data field (Annual Sales) but also the default summary operation (sum).
A Column Field
A Pivot Table column field works like a row field. A column field might be the variable
“Year” with values ranging from 1995 to 1998. Data beneath each column in the Pivot
Table is associated with the year at the head of the column.
6
The basic effect of row and column fields in a Pivot Table is that each value or item that
the field takes on defines a different row or column. So if a list has a row field with three
items (Schwinn, Cannondale, Omega) and a column field that with four items (1995,
1996, 1997, 1998), the Pivot Table has three rows and four columns, and therefore twelve
summary cells (exclusive of the cells that hold Grand Totals and labels).
A Data Field
The data field is the variable that the Pivot Table summarizes. For each combination of
values in the row and column fields, the data field takes on a different value and this
value appears in the Pivot Table’s cells.
When you define a Pivot Table you must identify a data field or Excel displays an error.
By contrast, however, you need not define either a row or a column field. If you build a
Pivot Table with a data field only Excel won’t display an error message but the Pivot
Table won’t provide a very meaningful result either. Without a row and/or column
“control”, Excel returns a simple table since it has no way to summarize the data.
There are many summarizing calculations available in a Pivot Table. Most often the data
to be summarized is numeric; the default summary for numeric data is a sum. For
example, if your Pivot Table data field is Total Sales, the field dialog for Total Sales
(below) shows that it can be summarized by sum, count, average, max, min, etc.
If the data to be summarized is text data, not numeric, the default summary is count. For
example “Employees” might be a data field and a Pivot Table might count of the
number of employees by department.
Custom calculations can be applied to the data field, including running totals, percent of
row, percent of column, and so on. If you need some calculation not provided within the
Pivot Table, you can perform that calculation outside the context of the Pivot Table.
Then you can include the calculated variable in your list when you start the Pivot Table
7
Wizard. The Pivot Table also has an option to create a calculated field and a calculated
item. To explore these options, check Excel’s Pivot Table online help.
Sum of Units Sold In the example at left, “Product” is considered an inner row
Region Product Total field while “Region” is the outer row field.
Northeast Brie 110
The effect of an inner field is to add another level of detail
Gouda 128 to the Pivot Table. Within one category, or value (such as
Northwest Brie 137 Northeast) of the outer field, there are two inner field
Gouda 151 values (Brie and Gouda).
Southeast Brie 63
Gouda 72 The data field is first summarized by the value of the outer
Southwest Brie 87 row field. Within that first-level summary, the data field is
Grand Total 748 further summarized by the corresponding values of the
inner row field.
Inner and outer column fields work the same way as inner and outer row fields.
8
The Pivot Table Page Field
The page field operates like the row and column fields but provides a third dimension to
your data. It allows you to add another variable to your Pivot Table without necessarily
viewing all its values at the same time.
9
Choose the Show Pages option at the bottom of the
PivotTable drop-down menu on the Pivot Table toolbar
to automatically generate a Pivot Table on a separate
worksheet for each page field possibility.
10
Dates used as row or column headers, for example, are often grouped for this reason.
11
Formatting Data in the Pivot Table
No matter what the format of the Pivot Table’s source data, the initial format of the data in a
Pivot Table is “General”. After creating a Pivot Table you can use Excel’s normal formatting
commands to format cells. To retain formatting when you refresh the data in a PivotTable or
change the layout, do the following:
• Click a cell in the PivotTable, and on the Pivot Table toolbar choose the Pivot Table
button, then Table Options. In the “Format options” part of the dialog that displays, make
sure the “Preserve formatting” check box is selected.
• Then, before you select the Pivot Table data you want to format, make sure that Pivot
Table “Enable Selection” is activated (Choose the Pivot Table button on the toolbar, then
Select, Enable Selection).
Without the steps above, if you make any change to your Pivot Table after you’ve applied
formatting (even if the change is only to refresh the data), your formatting is lost.
A good method for formatting a numeric Pivot Table data field is to use the formatting
options built into the Pivot Table itself. To do this:
1. Select any cell in the Pivot Table that represents its data field.
2. Click the Pivot Table Field button on the Pivot Table toolbar. The “Pivot Table Field”
dialog displays.
3. Click the Number button on this dialog to open the “Format Cells” dialog.
4. Choose one of the available formats, click OK to close the “Format Cells” dialog and
then OK again to close the “Pivot Table Field” dialog.
If you format your Pivot Table in this way, the formatting you select is retained even if you
change the layout of the Pivot Table. This formatting is for numeric data only, not for text
fields that might be used for row, column, or page fields.
12
To change the entire look of a Pivot Table, use the Pivot Table’s Format Report option
(available from the Pivot Table toolbar drop-down menu).
A new format you choose from the Pivot Table “AutoFormat” dialog remains with your
Pivot Table even if you refresh the data, pivot the table, or add or remove a field.
A table-style autoformat
leaves the data arrangement alone and adds just formatting such as bolding, reverse
video, etc. A report-style autoformat adds formatting but also rearranges the data so it’s
column-oriented.
13
Refreshing Pivot Table Data
A Pivot Table isn’t directly linked to its source data. Instead it’s linked to a hidden cache
that’s build from the data source. If you create a Pivot Table from, for example, a
worksheet list and then change the data in the list, the Pivot Table does not
automatically update. To update the Pivot Table, click any cell within the Table and click
the Refresh Data button (the red exclamation mark) on the Pivot Table toolbar. Then
Excel gets the new data from your changed Excel list. As an alternative you can also
right-click a cell in the Pivot Table and choose Refresh Data from the pop-up menu that
appears.
Ascending
Ascending
You may prefer to have your Pivot Table data sorted differently from the default. You
can sort the Pivot Table either by labels or by values. There are two ways to sort Pivot
Table data: “Externally” using Excel’s regular sorting feature, or “internally”, using the
internal Pivot Table sort option. The internal sort you set remains even if you refresh the
data (adding or deleting fields and values).
14
To Sort by Label using the “Internal” Method
If you choose to sort Pivot Table data using
Excel’s “external” sort, the “Sort” dialog that
displays reminds you that the Pivot Table
also has its own sort.
The advantage of the Pivot Table sort is that the sort is maintained even if the report
data is updated or its layout changed. To sort is this way, double-click either the row
field header or the column field header on which you want to sort. The Pivot Table
opens the field dialog for that field. In that dialog, choose the Advanced button to open
the Advanced Options field dialog, like the one illustrated below. Under “AutoSort
Options” choose Ascending or Descending. For the “Using field” box, choose the field
you’re sorting on. (A Manual sort is the default.)
15
To Sort by Pivot Table Data Values using the “Internal” Method
Double-click the field label associated with the item on which you want to sort to open
its field dialog. If you select a column label, items will be sorted from left to right. If you
select a row label, items will be sorted from top to bottom. In the field dialog box click
the Advanced button to open the “PivotTable Field Advanced Options” dialog. Under
“AutoSort options” choose Ascending or Descending. IMPORTANT: Then, in the “Using
field” box, choose the data field that has the values that you want to use to sort the items.
Text - Pivot Table Data Crunching, Jelen and Alexander, Que, 2006, ISBN 0-7897-3435-4.
Web – http://faculty.fuqua.duke.edu/~pecklund/ExcelReview/ExcelReview.htm
16
17