ExcelData3 PivotTables
ExcelData3 PivotTables
[email protected]
Excel Data 3: PivotTables
1.5 hour Classroom* / 1.0 hour Zoom Session
* Classroom sessions include time to repeat exercises for practice
PivotTables .................................................................................................................................................... 3
Planning..................................................................................................................................................... 3
Building ..................................................................................................................................................... 4
Arranging Fields ........................................................................................................................................ 5
Formatting................................................................................................................................................. 6
Pivot Tables - Excel 2016 Help File ................................................................................................................ 7
Create a PivotTable ................................................................................................................................... 7
Working with the PivotTable Fields list..................................................................................................... 8
PivotTable Values ...................................................................................................................................... 8
Refreshing PivotTables ............................................................................................................................ 10
Create a PivotChart ................................................................................................................................. 10
Change the source data .......................................................................................................................... 11
Delete a PivotTable ................................................................................................................................. 11
Class Exercises ............................................................................................................................................. 12
Filters....................................................................................................................................................... 12
Favorite Colors ........................................................................................................................................ 13
Average Income ...................................................................................................................................... 13
Range (High/Low) .................................................................................................................................... 14
First/Last Date ......................................................................................................................................... 14
Grouping Dates ....................................................................................................................................... 15
Grouping Text with no Summary Values ................................................................................................ 15
PivotChart ............................................................................................................................................... 16
PivotChart Filtered Title .......................................................................................................................... 17
Things to Remember ................................................................................................................................... 18
Updated: 6/27/2022
PivotTables
PivotTables are summary reports. They give you the ability to take a large boring set of repetitive data
and summarize it into a neat table that you can very easily rearrange, filter, format, and even chart.
Here's an example of a repetitive raw data set, three PivotTables, and a PivotChart.
Planning
The most important part of building a PivotTable is planning. You have to remove yourself from the raw
data and think about the final result. There is a learning curve, have patience with yourself and with
Excel and you'll get there.
The Data
The data has to be repetitive. It looks wrong at first, but the more boring and repetitive your data, the
more you can do with it. In the Large Data 1 class we learn about sorting and filtering in Excel. We don't
need to keep each quarter, each department, each person on a different sheet. If we keep all of the data
in the same place, we can look at each category, one at a time, using the filter, and beautifully because it
is all in the same place, we can look across categories and quickly summarize with a PivotTable.
The data has to be consistent. We don't want to see entries like: 4th Qtr, 4th Quarter, Qtr 4. In the
Large Data 3 (vLookups) class we'll learn about validation rules, and in Large Data 4 (report) we'll see
how to use vLookups to help us cleanup inconsistent data entry.
The definition of a database is a structured collection of related data. Rows of a data table are records.
When we filter in Excel, the Status Bar tells us how many Records were found.
Columns of a data table are fields. The column titles of your original dataset will appear in the
PivotTable Field List. You will use these titles to control the structure of the PivotTable. If possible, use
clear, concise, and unique column titles. If you use the same column title more than once, Excel will add
a number after the subsequent titles. Example: Home Address, City, State, Zip, Work Address, City, State,
Zip becomes Home Address, City, State, Zip, Work Address, City(2), State(2), Zip(2).
3
The Result
By all means, jump in and play with the tools, get comfortable with how to make a PivotTable. But when
it comes down to needing a specific report, you have to "show your work". Think about what it is you
actually want to see.
"I want to know how many items we ordered." Okay. Do you care what the items were? Do you care
about the data across the year, or do you only want the total? What about the other details? Each
versus boxes? Would you like to compare your orders to another departments?
"I want to know how many patients were admitted last month." Okay. Do you want to see the break
down by time, perhaps by morning and afternoon? By shift? By Department? Or would you like to have
the flexibility to change (filter) the shifts and departments?
The more you think about what you want out of the glorious summary report known as a PivotTable, the
better it will come together for you.
Building
The PivotTable field list shows the column titles of our original dataset, these are our Fields. If you
rename, add, or delete columns in the dataset you will not see the change here until you refresh the
data. The Refresh button is on the Analyze tab of the PivotTable Tools, and can be found on the shortcut
menu if you right-click inside the table.
4
Arranging Fields
Adding
• Click the check box in front of the field name
− Text fields will go into the Rows showing each unique value from the dataset
− Date fields will go into the Rows grouping the values across time
− Number fields will go into the Value as a sum
• Drag fieldname from the field list to an area
− You will have to drag to add a field to the value area multiple times
• Right-click on the fieldname in the field list and choose an area
Moving
• Drag fieldname from an area to a new area
• Right-click on the fieldname in the field list and choose a new area
• Left-click on a field in an area and choose a new area
Deleting
• Drag fieldname out of the area section
• Left-click on a field in the area and choose Remove Field
You can reformat your numbers with the Excel formatting tools, but if you reformat from the Value Field
Settings window you'll format the Table, this means if you change the structure of your table by adding
fields you won't have to reformat any new cells occupied by the table.
5
Formatting
The PivotTable Design tab has lots of style options to make the PivotTable look good. Change the
Options settings to see how they vary in the style you chose.
The style options help with the look of the data, but in my opinion
the first set of buttons on the Design tab are way better, as they
determine how the data is pulled together within the PivotTable.
6
Pivot Tables - Excel 2016 Help File
Create a PivotTable
If you have limited experience with PivotTables, or are not sure how to get started, a Recommended
PivotTable is a good choice. When you use this feature, Excel determines a meaningful layout by
matching the data with the most suitable areas in the PivotTable. This helps give you a starting point for
additional experimentation. After a recommended PivotTable is created, you can explore different
orientations and rearrange fields to achieve your specific results.
Recommended PivotTable Manually create a PivotTable
1. Click a cell in the source data or table 1. Click a cell in the source data or table range.
range. 2. Go to Insert > Tables > PivotTable.
2. Go to Insert > Tables > Recommended
PivotTable.
7
Working with the PivotTable Fields list
In the Field Name area at the top, select the check box for any field you want to add to your PivotTable.
By default, non-numeric fields are added to the Row area, date and time fields are added to the Column
area, and numeric fields are added to the Values area. You can also manually drag-and-drop any
available item into any of the PivotTable fields, or if you no longer want an item in your PivotTable,
simply drag it out of the Fields list or uncheck it. Being able to rearrange Field items is one of the
PivotTable features that makes it so easy to quickly change its appearance.
PivotTable Values
• Summarize Values By
By default, PivotTable fields that are placed in the Values area will
be displayed as a SUM. If Excel interprets your data as text, it will
be displayed as a COUNT. This is why it's so important to make
sure you don't mix data types for value fields. You can change the
default calculation by first clicking on the arrow to the right of the
field name, then select the Value Field Settings option.
8
Next, change the calculation in the
Summarize Values By section. Note that
when you change the calculation
method, Excel will automatically append
it in the Custom Name section, like "Sum
of FieldName", but you can change it. If
you click the Number Format button,
you can change the number format for
the entire field.
• Show Values As
Instead of using a calculation to summarize the data, you can also display it as a percentage of a
field. In the following example, we changed our household expense amounts to display as a % of
Grand Total instead of the sum of the values.
9
Refreshing PivotTables
If you add new data to your PivotTable data source, any PivotTables
that were built on that data source need to be refreshed.
If you have multiple PivotTables, first select any cell in any PivotTable,
then on the Ribbon go to PivotTable Tools > Analyze > Data > Click
the arrow under the Refresh button and select Refresh All.
Create a PivotChart
1. Click anywhere in the PivotTable to show the PivotTable Tools on the ribbon.
2. Click Analyze > PivotChart.
After you create a PivotChart, you can customize it, much like you’d do with any standard charts.
When you select the PivotChart two buttons appear
next to the chart so you can quickly add or change
chart elements such as titles or data labels, or change
the chart style and colors of your PivotChart the same
way you would in a standard chart.
The PivotChart Tools are shown on the ribbon.
On the Analyze, Design, and Format tabs, you can
pick options to work with or customize your
PivotChart.
10
Change the source data
After you create a PivotTable, you can change the range of its source data. For example, you can expand
the source data to include more rows of data. However, if the source data has been changed
substantially—such as having more or fewer columns, consider creating a new PivotTable.
To change the data source of a PivotTable if it's a range of cells or an Excel table, do the following:
Tip: Leave the dialog box open, and then select the table or range on your worksheet. If the data you
want to include is on a different worksheet, click that worksheet, and then select the table or range.
Delete a PivotTable
When you no longer need a PivotTable, select the entire PivotTable, and press the Delete key to remove
it. If you get a "Cannot change this part of a PivotTable report" message, make sure the entire
PivotTable is selected. Press Ctrl+A, and press Delete again.
If you're using a device that doesn't have a keyboard, try removing the PivotTable like this:
1. Pick a cell anywhere in the PivotTable to show the PivotTable Tools on the ribbon.
3. Press Delete.
11
Class Exercises
Filters
1) Open File: PivotSales.xlsx
• If necessary, move to cell A1
2) From the Insert tab, choose PivotTable
• Click OK to make a new PivotTable based on the
current dataset on a new worksheet.
3) Set up the table to look like this:
RESULT
12
Favorite Colors
1) Open File: PivotSurvey.xlsx
• If necessary, move to cell A1
2) From the Insert tab, choose PivotTable
• Choose Existing Worksheet
• Type in G5 and click OK
3) Add Fav Color to the Rows
4) Add Fav Color to the Values RESULT
• Since Fav Color is text, we get COUNT
5) Sort the values so the most popular color is first
• Click on a number in the table, choose sort descending
from the ribbon or right-click menu
• From the PivotTable Tools Analyze Tab, Move PivotTable to
a new sheet, or Clear All.
Average Income
1) Recreate PivotTable structure, if necessary, otherwise skip to step 2
• Open File: PivotSurvey.xlsx
• move to cell A1
• From the Insert tab, choose PivotTable
• Choose Existing Worksheet
• Type in G5 and click OK
2) Use fields Fav Color, Degree, Income
3) In the Values area of the field list, click on
Income, choose Value Field Settings
4) Choose Average
5) Click Number Format
• Set as a number with a comma and zero
decimals
RESULT
The blank values in the table mean there's no data
that matches the grouping. If you would prefer to
see something, such as a zero or N/A:
- Click the Options button, on the far left side of
the Analyze tab.
- On the first page of the options window,
Layout & Formatting, put what you would like
to see in the For Empty Cells Show: option.
13
Range (High/Low)
1) Open File: PivotKangarooRats.xlsx
• If necessary, move to cell A1
2) From the Insert tab, choose PivotTable
• Choose Existing Worksheet
• Type in F10 and click OK
First/Last Date
Repeat this exercise but use the Date as the value. Minimum
dates are Earliest, Maximum are Latest. Don't forget to reformat
the date as a Date!
• From the PivotTable Tools Analyze Tab, Move
PivotTable to a new sheet, or Clear All.
14
Grouping Dates
We want the average weight, with zero decimals for all
the rats by months and years.
1) Recreate PivotTable structure, if necessary,
otherwise skip to step 2
• Open File: PivotKangarooRats.xlsx
• Move to cell A1
• From the Insert tab, choose PivotTable
• Choose Existing Worksheet
• Type in G5 and click OK
2) In the field list, click the checkbox for the Date
field to add it to the Rows area
• Try the +/- (expand/collapse) buttons to see
the different date groupings
• Notice the new fields in the field list
• This happens automatically, if all the values are
dates. If even a single cell in the original data
column is not a date, you will not be able to
group. Use your sort tools on the original data
to find the values that don't belong.
3) From the PivotTable Tools Analyze Tab, Move PivotTable to a new sheet, or Clear All.
RESULT
15
PivotChart
When you create a PivotChart, Excel will create a PivotTable
to support the chart. I recommend building the PivotTable
before creating the chart.
1) Open File: PivotSales.xlsx
• If necessary, move to cell A1
2) From the Insert tab, choose PivotTable
• Click OK to make a new PivotTable based on the
current dataset on a new worksheet.
3) Create this table:
RESULT
16
PivotChart Filtered Title
1) Add the field Quarter to the PivotChart's
Filters area
4) Click anywhere in the chart. Look for the big plus sign in the
upper right hand corner. Click on it and choose Chart Title.
5) Click on the newly created Chart Title. Do not type inside the
title, instead once it's selected click in the formula bar.
RESULT
17
Things to Remember
1) Pivot Tables and the source data don't have to exist in the same workbook. If you forgot where
the original data is located, go to the Change Data Source option on the Analyze tab.
2) Double-clicking on a cell within the PivotTable will create a copy of the breakdown of the data
inside a table on a new sheet. This is a COPY and not linked to the original in any way. I
recommend deleting it, or moving it to a different workbook.
3) To move a sheet to a different book, right-click on the sheet name and choose Move or Copy…
change the dropdown To Book.
4) The +/- Buttons will expand and collapse the grouped data for that entry. You can do the entire
group at once from the Expand Field and Collapse Field buttons in the PivotTable Analyze tab.
The option to turn off the +/- buttons is on the far right side of the Analysis tab.
5) Changing the Report Layout on the PivotTable Tools Design tab to Outline or Layout will give
each field name its own filter arrow and title.
6) Report filters are meant for one choice. If you want multiple choices include the field in the
PivotTable, or try a Slicer instead.
8) Can't undo? Afraid you messed everything up? Close without saving. It's the Ultimate Undo, or
use F12 on the keyboard to Save As a new file.
9) My email address and phone number are on the second page of this packet!
Source: http://media.news.health.ufl.edu/misc/training/Handouts/zoom/Excel/ExcelData3-PivotTables.pdf
18