Pivot Table
Pivot Table
1
A pivot table is essentially a dynamic summary report generated from a database
A pivot table can help transform endless rows and columns of numbers into a
meaningful presentation of the data
In addition, you can display subtotals and any level of detail that you want
After you create a pivot table, you can rearrange the information in almost any way
imaginable and even insert special formulas that perform new calculations
One minor drawback to using a pivot table is that, unlike a formula-based summary
report, a pivot table does not update automatically when you change information in
the source data
A single click of the Refresh button forces a pivot table to update itself with the latest
data
Pivot Tables Example
3
Pivot Tables Example
The table contains 712 rows, and each row represents a new account opened at the bank.
The table has the following columns:
4
Pivot Tables Example
To make the data more useful, you need to summarize it. Summarizing a database is essentially
the process of answering questions about the data.
5
Data Appropriate for Pivot Table
Necessary conditions
• Each column of the Pivot Table must have a title.
• The title should be written in a single row.
• In a column, all the items should be of the same data type
(numbers, dates or strings).
• The data table should not contain any merged cells.
• The data table should not contain subtotals or grand totals
(unless you use a dynamic table).
• Empty rows or columns should not remain within the table
(if an empty row or column remains, Excel will treat the
table as two different ones).
• After creating a pivot table, do not change the titles of the
fields, otherwise the pivot table values will be deleted.
6
Data Appropriate for Pivot Table
Desirable conditions
• Unique names for each column
(when two fields are given the same name, the title
of the second field will be appended at end with 2,
i.e. “salary2″).
• Complete data for all records
(when data is missing, the calculations will only be
applied to the available records. This can be
observed in the cases of calculations such as
averages, etc).
7
Data Appropriate for Pivot Table
Fields in a database table consist of two types of information:
■ Data: Contains a value or data to be summarized. For the bank account example, the
Amount field is a data field.
■ Category: Describes the data. For the bank account data, the Date, Weekday, AcctType,
OpenedBy, Branch, and Customer fields are category fields because they describe the data in
the Amount field.
8
Data Appropriate for Pivot Table
A database table that’s appropriate for a pivot table is said to be “normalized.” In other
words, each record (or row) contains information that describes the data.
Fig 4. An Excel range that is not appropriate Fig 5. The same data as in Fig 4, but normalized. Ideal
for a pivot table candidate for a pivot table
9
Create a Pivot Table
To create a Pivot Table, you have 2 options:
• Use the Recommended Pivot Tables option (Insert >> Tables >> Recommended Pivot
Tables), then use the PivotTable Field task pane to modify it
• Click the Blank PivotTable button (at the bottom of the Recommended PivotTables dialog
box) and create a pivot table manually.
10
Lay out the Pivot Table
The next step is to set up the actual layout of the pivot table. The easiest way is to drag the
field names (at the top of the PivotTable Fields task pane) to one of the four boxes at the
bottom of the task pane.
Fig 6. Drag the field names to the boxes to create the pivot table
11
The following steps create the pivot table
1. Drag the Amount field into the Values area. At this point, the pivot table
displays the total of all the values in the Amount column.
2. Drag the AcctType field into the Rows area. Now the pivot table shows the total
amount for each of the account types.
3. Drag the Branch field into the Columns area. The pivot table shows the
amount for each account type, cross-tabulated by branch. The pivot table
updates itself automatically with every change you make in the PivotTable
Fields task pane.
4. Right click any cell in the pivot table and choose Number Format. Excel displays
the Number tab of the Format Cells dialog box.
5. Select a number format and click OK. Excel applies the format to all numeric cells
in the pivot table.
12
13
Pivot Table Terminology
• Column /Row labels: A field that has a column /row orientation in the pivot table. Each item in the
field occupies a column /row. Ex: The column field here shows the branch field
• Grand totals: A row or column that displays totals for all cells in a row or column in a pivot table.
• Item: An element in a field that appears as a row or column header in a pivot table. Ex: in the
branch column field, there are 4 items (Central, North County, and Westside).
• Values area: The cells in a pivot table that contain the summary data. Excel offers several ways to
summarize the data (sum, average, count, and so on). Ex: Here, drag the amount field to the values
area, then right click to format it to calculate the sum.
• Filters: A field that has a page orientation in the pivot table. You can display one item, multiple
items, or all items in a page field at onetime. Ex: Only the existing customers are shown here
14
Group: A collection of items treated as a single item. You can group items manually
or automatically (group dates into months, for example). The pivot table in the figure
does not have defined groups.
Refresh: Recalculates the pivot table after making changes to the source data.
Row labels: A field that has a row orientation in the pivot table. Each item in the
field occupies a row. You can have nested row fields. In the figure, both Branch and
AcctType represent row fields.
Source data: The data used to create a pivot table. It can reside in a worksheet or
an external database
Subtotals: A row or column that displays subtotals for detail cells in a row or
column in a pivot table. The pivot table in the fi gure displays subtotals for each
branch, below the data. You can also display subtotals above the data or hide
subtotals.
15
16
More Pivot Table Examples
Pivot Tables are used to summarize the data and answer
questions.
Question 1: What is the daily total new deposit amount
for each branch?
■ The Branch field is in the Columns section.
■ The Date field is in the Rows section.
■ The Amount field is in the Values section and is
summarized by Sum.
Sorting is available in any column. Ex: you can sort the
Grand Total column in descending order to find out which
day of the month had the largest amount of new funds.
Right click any cell in the column >> Sort
17
More Pivot Table Examples
Question 2: Which day of the week accounts for the most deposits?
■ The Weekday field is in the Rows section.
■ The Amount field is in the Values section and is summarized by Sum.
Conditional formatting data bars is added to make it easier to see how the days compare. As you
see, the largest deposit days are Fridays.
Reminder: Home >> Style >> Conditional Formatting >> Data Bars
18
More Pivot Table Examples
Question 3: How many accounts were opened at each branch, broken down by account type?
■ The AcctType field is in the Columns section.
■ The Branch field is in the Rows section.
■ The Amount field is in the Values section and is summarized by Count.
So far, all the pivot table examples have used the Sum summary
function. In this case, I changed the summary function to Count.
Right click any cell in the Value areas >> Summarize Values By
>> Count
19
More Pivot Table Examples
Question 4: What’s the dollar distribution of the different account types?
■ The Amount field is in the Rows section (grouped, to show dollar ranges).
■ The Amount field is also in the Values section and is summarized by Count.
■ A third instance of the Amount field is the Values section, summarized by Count
21
More Pivot Table Examples
Question 5: What types of accounts do tellers open most often?
■ The AcctType field is in the Rows section.
■ The OpenedBy field is in the Filters section.
■ The Amount field is in the Values section (summarized by Count).
■ A second instance of the Amount field is in the Values section (summarized by % of Column Total)
22
More Pivot Table Examples
Question 6: In which branch do tellers open the most checking accounts for new customers?
■ The Customer field is in the Filters section.
■ The OpenedBy field is in the Filters section.
■ The AcctType field is in the Filters section.
■ The Branch field is in the Rows section.
■ The Amount field is in the Values section, summarized by Count.