Sample
Sample
Bill Jelen
Michael Alexander
Microsoft Excel 2019 Pivot Table Data Crunching
Published with the authorization of Microsoft Corporation by:
Pearson Education, Inc.
Copyright © 2019 by Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must
be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any
form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions,
request forms, and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please
visit www.pearsoned.com/permissions/. No patent liability is assumed with respect to the use of the information contained
herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information
contained herein.
ISBN-13: 978-1-5093-0724-1
ISBN-10: 1-5093-0724-9
Library of Congress Control Number: 2018963618
Printed in the United States of America
1 18
Trademarks
Microsoft and the trademarks listed at http://www.microsoft.com on the “Trademarks” webpage are trademarks of the
Microsoft group of companies. All other marks are property of their respective owners.
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic
versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding inter-
ests), please contact our corporate sales department at [email protected] or (800) 382-3419.
For government sales inquiries, please contact [email protected].
For questions about sales outside the U.S., please contact [email protected].
Editor-in-Chief: Brett Bartow
Executive Editor: Loretta Yates
Sponsoring Editor: Charvi Arora
Managing Editor: Sandra Schroeder
Senior Project Editor: Tracey Croom
Project Editor: Charlotte Kughen
Copy Editor: Kitty Wilson
Indexer: Ken Johnson
Proofreader: Paula Lowell
Technical Editor: Bob Umlas
Publishing Coordinator: Cindy Teeters
Cover Designer: Twist Creative, Seattle
Compositor: Bronkella Publishing LLC
Graphics: TJ Graham Art
To Ashvina Sharma and his team at Microsoft. Thanks for Pivot
Table Defaults!
—Bill Jelen
To my 12 fans at datapigtechnologies.com.
—Mike Alexander
Contents at a Glance
Introduction xxiii
Index 443
v
Contents
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Contents ix
Grouping date fields by week . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
AutoGrouping pivot table dates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Understanding how Excel decides what to AutoGroup. . . . . . . . . . . . 111
Using AutoGroup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Creating an easy year-over-year report. . . . . . . . . . . . . . . . . . . . . . . . . . 113
Creating hierarchies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Next steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
x Contents
Keeping pivot chart rules in mind. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Changes in the underlying pivot table affect a pivot chart . . . . . . . 154
Placement of data fields in a pivot table might not be best
suited for a pivot chart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
A few formatting limitations still exist in Excel 2019. . . . . . . . . . . . . . 156
Examining alternatives to using pivot charts . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Method 1: Turn the pivot table into hard values. . . . . . . . . . . . . . . . . . 162
Method 2: Delete the underlying pivot table. . . . . . . . . . . . . . . . . . . . 162
Method 3: Distribute a picture of the pivot chart . . . . . . . . . . . . . . . . 163
Method 4: Use cells linked back to the pivot table as the source
data for the chart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Using conditional formatting with pivot tables. . . . . . . . . . . . . . . . . . . . . . . . 165
An example of using conditional formatting . . . . . . . . . . . . . . . . . . . . 165
Preprogrammed scenarios for condition levels. . . . . . . . . . . . . . . . . . 167
Creating custom conditional formatting rules. . . . . . . . . . . . . . . . . . . . . . . . . 168
Using Power BI Custom Visuals in Excel . . . . . . . . . . . . . . . . . . . . . . . . . 173
Next steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Contents xi
Power Query connection types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
One more Power Query example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Next steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
xii Contents
Breaking out of the pivot table mold with cube functions. . . . . . . . . . . . . . 248
Exploring cube functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Adding calculations to OLAP pivot tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Creating calculated measures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Creating calculated members. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Managing OLAP calculations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Performing what-if analysis with OLAP data. . . . . . . . . . . . . . . . . . . . . 258
Next steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Contents xiii
Chapter 11 Analyzing geographic data with 3D Map 289
Analyzing geographic data with 3D Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Preparing data for 3D Map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Geocoding data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Building a column chart in 3D Map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Navigating through the map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Labeling individual points. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Building pie or bubble charts on a map. . . . . . . . . . . . . . . . . . . . . . . . . 294
Using heat maps and region maps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Exploring 3D Map settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Fine-tuning 3D Map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Combining two data sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Animating data over time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Building a tour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Creating a video from 3D Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Next steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
xiv Contents
Learning tricks of the trade. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Writing code to handle a data range of any size. . . . . . . . . . . . . . . . . 327
Using super-variables: Object variables. . . . . . . . . . . . . . . . . . . . . . . . . 328
Using With and End With to shorten code. . . . . . . . . . . . . . . . . . . . . . 329
Understanding versions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Building a pivot table in Excel VBA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Adding fields to the data area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Formatting the pivot table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Dealing with limitations of pivot tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Filling blank cells in the data area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Filling blank cells in the row area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Preventing errors from inserting or deleting cells. . . . . . . . . . . . . . . . 336
Controlling totals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Converting a pivot table to values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
Pivot table 201: Creating a report showing revenue by category. . . . . . . . 341
Ensuring that Tabular layout is utilized. . . . . . . . . . . . . . . . . . . . . . . . . . 344
Rolling daily dates up to years. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Eliminating blank cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Controlling the sort order with AutoSort. . . . . . . . . . . . . . . . . . . . . . . . 347
Changing the default number format. . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Suppressing subtotals for multiple row fields. . . . . . . . . . . . . . . . . . . . 348
Copying a finished pivot table as values to a new workbook . . . . . 349
Handling final formatting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Adding subtotals to get page breaks. . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Putting it all together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Calculating with a pivot table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Addressing issues with two or more data fields. . . . . . . . . . . . . . . . . . 355
Using calculations other than Sum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Using calculated data fields. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Using calculated items. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Calculating groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Using Show Values As to perform other calculations. . . . . . . . . . . . . 362
Using advanced pivot table techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Using AutoShow to produce executive overviews. . . . . . . . . . . . . . . . 365
Using ShowDetail to filter a Recordset. . . . . . . . . . . . . . . . . . . . . . . . . . 367
Contents xv
Creating reports for each region or model. . . . . . . . . . . . . . . . . . . . . . 369
Manually filtering two or more items in a pivot field. . . . . . . . . . . . . 373
Using the conceptual filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Using the search filter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Setting up slicers to filter a pivot table. . . . . . . . . . . . . . . . . . . . . . . . . . 378
Using the Data Model in Excel 2019. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Adding both tables to the Data Model. . . . . . . . . . . . . . . . . . . . . . . . . . 381
Creating a relationship between the two tables . . . . . . . . . . . . . . . . . 382
Defining the pivot cache and building the pivot table. . . . . . . . . . . . 383
Adding model fields to the pivot table. . . . . . . . . . . . . . . . . . . . . . . . . . 383
Adding numeric fields to the Values area. . . . . . . . . . . . . . . . . . . . . . . . 383
Putting it all together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Next steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
xvi Contents
Tip 14: Format individual values in a pivot table . . . . . . . . . . . . . . . . . . . . . . . 405
Tip 15: Format sections of a pivot table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Tip 16: Create a frequency distribution with a pivot table. . . . . . . . . . . . . . . 409
Tip 17: Use a pivot table to explode a data set to different tabs. . . . . . . . . 410
Tip 18: Apply restrictions on pivot tables and pivot fields. . . . . . . . . . . . . . . 412
Pivot table restrictions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Pivot field restrictions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Tip 19: Use a pivot table to explode a data set to different workbooks. . 415
Tip 20: Use percentage change from previous for year-over-year . . . . . . 417
Tip 21: Do a two-way VLOOKUP with Power Query. . . . . . . . . . . . . . . . . . . . 419
Next steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Contents xvii
Acknowledgments
Thanks to Mike Alexander for being my coauthor on the five previous editions of this
book. At Microsoft, thanks to the Excel team for always being willing to answer questions
about various features. At MrExcel.com, thanks to an entire community of people who are
passionate about Excel. Finally, thanks to my wife, Mary Ellen, for her support during the
writing process.
—Bill Jelen
Thanks to Bill Jelen for deciding to coauthor this book with me many editions ago. His
knowledge of Excel still blows me away to this day. My deepest thanks to the professionals
at Pearson Education for all the hours of work put into bringing this book to life. Thanks
also to Bob Umlas, whose technical editing has helped us make numerous improvements
to the examples and text in this book. Finally, a special thank you goes to the wife and kids
for putting up with all the time I spent locked away on this project.
—Mike Alexander
Acknowledgments xix
About the Authors
Bill Jelen, Excel MVP and the host of MrExcel.com, has been using spreadsheets since
1985, and he launched the MrExcel.com website in 1998. Bill was a regular guest on Call
for Help with Leo Laporte and has produced more than 2,200 episodes of his daily video
podcast, Learn Excel from MrExcel. He is the author of 57 books about Microsoft Excel
and writes the monthly Excel column for Strategic Finance magazine. Before founding
MrExcel.com, Bill spent 12 years in the trenches, working as a financial analyst for the
finance, marketing, accounting, and operations departments of a $500 million public
company. He lives in Merritt Island, Florida, with his wife, Mary Ellen.
The pivot table is the single most powerful tool in all of Excel. Pivot tables came along
during the 1990s, when Microsoft and Lotus were locked in a bitter battle for domi-
nance of the spreadsheet market. The race to continually add enhanced features to their
respective products during the mid-1990s led to many incredible features, but none as
powerful as the pivot table.
With a pivot table, you can transform one million rows of transactional data into a
summary report in seconds. If you can drag a mouse, you can create a pivot table. In
addition to quickly summarizing and calculating data, pivot tables enable you to change
your analysis on the fly by simply moving fields from one area of a report to another.
No other tool in Excel gives you the flexibility and analytical power of a pivot table.
Having picked up this book, you are savvy enough to have heard of pivot tables—and
you have perhaps even used them on occasion. You have a sense that pivot tables pro-
vide a power that you are not using, and you want to learn how to leverage that power to
increase your productivity quickly.
Within the first two chapters, you will be able to create basic pivot tables, increase
your productivity, and produce reports in minutes instead of hours. Within the first seven
chapters, you will be able to output complex pivot reports with drill-down capabilities
and accompanying charts. By the end of the book, you will be able to build a dynamic
pivot table reporting system.
xxiii
■■ You can specify default settings for all future pivot tables. If you want all pivot
tables to start in Tabular layout instead of Compact layout, you can specify this.
Do you prefer Classic layout or do you always replace empty cells with zero? Visit
File, Options, Data, Pivot Table Defaults to change the settings for all future pivot
tables.
■■ The automatic date grouping introduced in Excel 2016 pivot tables can now be
turned off. The setting is found in File, Options, Data. The feature became un-
popular after the release of Excel 2016.
■■ Pivot tables will be doing more summing and less counting. Previously, if you had
a column with revenue and a few empty cells, the pivot table would choose to
Count instead of Sum. In Excel 2019, a mix of empty cells and numeric cells will be
treated like a numeric column and will default to Sum instead of Count.
■■ Power Pivot is now included in all Windows versions of Excel 2019 and Office 365.
During the tenure of Office 2013–2016, only parts of Power Pivot were available.
Although some of the Power Pivot functionality was available if you chose Add
This Data To The Data Model while creating a pivot table, you can now access the
Power Pivot tab in the ribbon. This allows you to create and view relationships in a
diagram view. You can choose to sort one column by another column.
■■ With Power Pivot in Excel 2019, your pivot tables benefit from any new functions
added to the DAX formula language. If you ever wanted to do Median in a pivot
table or even report Text fields in the Values area, the new DAX functions such as
MEDIAN and CONCATENATEX allow this to happen.
■■ Power View is being de-emphasized. Microsoft is replacing Power View with Power
BI Desktop. You will find it difficult to locate the Power View icons in Excel 2019.
■■ If you are using Office 365, you will have access to the Insights command on the
Insert tab. This command uses artificial intelligence to suggest 30 interesting
charts or pivot tables that can be created from your data.
xxiv Introduction
3. Delete the Product heading.
4. Copy the unique list of products and then use Paste Special Transpose to
turn the list sideways.
9. Cut and paste the products so they appear to the left of and below the
regions.
At this point, with 27 mouse clicks or keystrokes, you’ve built the shell of the
final report, but there are no numbers inside yet (see Figure I-1).
Next, you need to build the relatively new SUMIFS function to total the rev-
enue for the intersection of a region and product. As shown in Figure I-2, the
formula =SUMIFS($G$2:$G$564,$C$2:$C$564,L$1,$B$2:$B$564,$K2) does the
trick. It takes 52 characters plus the Enter key to finish the formula, but I man-
aged to enter the formula in 36 clicks or keystrokes by using some clever navi-
gation tricks I’ve learned over the years.
If this were the year 2006, the SUMIFS function would have been an uglier
FIGURE I-2
SUMPRODUCT function.
If you are adept at using the Fill handle, you need just two more mouse drags
to copy the formula to the rest of the table.
Introduction xxv
Enter the heading Total for the total row and for the total column. You can do
this in nine keystrokes if you type the first heading, press Ctrl+Enter to stay in
the same cell, and then use Copy, select the cell for the second heading, and
use Paste.
If you select K1:P6 and press Alt+= (that is, Alt and the equal sign key), you can
add the total formula in three keystrokes.
With this method, which takes 77 clicks or keystrokes, you end up with a nice
summary report, as shown in Figure I-3. If you could pull this off in 5 or 10
minutes, you would probably be fairly proud of your Excel prowess; there are
some good tricks among those 77 operations.
You hand the report to your manager. Within a few minutes, he comes back
with one of the following requests, which will certainly cause a lot of rework:
■■ Could you put products down the side and regions across the top?
■■ Could you show me the same report for only the manufacturing customers?
The core concept behind a pivot table is that the data, formulas, and data views are
stored separately. Each column has a name, and you can group and rearrange the data
by dragging field names to various positions on the report.
xxvi Introduction
Case Study: Life After Pivot Tables
Say that you’re tired of working so hard to remake reports every time your
manager wants a change. You’re in luck: You can produce the same report as
in the last case study but use a pivot table instead. Excel 2019 offers you 10
thumbnails of recommended pivot tables to get you close to the goal. Follow
these steps:
1. Click the Insert tab of the ribbon.
FIGURE I-4 The first recommended pivot table is as close as you will get to the required
report.
4. Drag the Product field from the PivotTable Fields list to the Columns area
(see Figure I-5).
Introduction xxvii
FIGURE I-5 To finish the report, drag the Product heading to the Columns area.
With just five clicks of the mouse, you have the report shown in Figure I-6.
In addition, when your manager comes back with a request like the ones near
the end of the prior case study, you can easily use the pivot table to make the
changes. Here’s a quick overview of the changes you’ll learn to make in the
chapters that follow:
■■ Could you put products down the side and regions across the top? (This
change will take you 10 seconds: Drag Product to Rows and Region to Col-
umns.)
■■ Could you show me the same report for only the manufacturing customers?
(15 seconds: Select Insert Slicer, Sector; click OK; click Manufacturing.)
xxviii Introduction
■■ Could you show profit instead of revenue? (10 seconds: Clear the check box
for Revenue, select the check box for Profit.)
■■ Could you copy this report for each of the customers? (30 seconds: Move
Customer to Report Filter, open the tiny drop-down menu next to the Op-
tions button, choose Show Report Filter Pages, click OK.)
Here’s why the authors hope that you did not purchase Office 2019: The features
in Office 2019 will not change. The features in Office 365 will constantly evolve and
improve. The people who have been using Office 365 have enjoyed the new features
described earlier in this chapter one to two years before the people who purchased Of-
fice 2019.
Because the title of this book says Excel 2019, the screenshots show the Excel 2019 rib-
bon. However, anyone using Office 365 will have a new look to the ribbon.
Microsoft reduced the number of colors in the Office 365 ribbon. The selected Ribbon
tab is now underlined instead of being a different color. Compare the Excel 2019 Insert
tab in Figure I-7 with the Office 365 Insert tab in Figure I-8.
FIGURE I-7 The Excel 2019 ribbon is very similar to the Excel 2016 ribbon.
Introduction xxix
FIGURE I-8 The Office 365 ribbon introduced in the summer of 2018 uses a new font and fewer
colors.
Microsoft is experimenting with a new ribbon that goes back to a single row like the
Office 2013 menus. As of the summer of 2018, that new ribbon will debut with Outlook
and Excel Online and only for Office 365 customers. It remains to be seen if that ribbon
ever makes it to the desktop version of Excel.
For any new features introduced to Office 365, the owners of Excel 2019 will have to
purchase Office 2022 in order to access those features.
But what is even worse, some features introduced will be marked as Office 365 Exclu-
sive features. Those features will never be available to customers who buy the perpetual
versions of Office, such as Office 2016, Office 2019, or Office 2022.
One such feature introduced in early 2018 is the Insights feature. This feature will send
up to 250,000 cells of your data to a Microsoft server where artificial intelligence looks for
trends in your data. The first few results from Insights are very similar to the Insert Recom-
mended PivotTable logic introduced in Excel 2013 and shown previously in Figure I-4.
However, if you click the More link, Insights often provides two to three dozen sug-
gestions. Most suggestions will insert a pivot table and a pivot chart. In the first preview
of Insights, Excel will look for: rank, evenness, trend, composite signal, attribution, out-
standing top two, monotonicity (always increasing or always decreasing), and unimodal-
ity (having a single peak data point).
When I used the data set from this Introduction with Insights in Office 365, Microsoft
suggested 32 different possible results. One is shown in Figure I-9.
xxx Introduction
FIGURE I-9 Excel used artificial intelligence to spot these outliers.
If you regularly purchased every new version of Office, it will cost less to rent Office
365 at $10 a month than to pay $399 for the perpetual version of Office every 36 months.
Office 365 offers more features than Excel 2019. Unless your buying pattern is to only
buy every second or third version of Office, upgrading to Office 365 makes sense.
We assume that you are comfortable navigating in Excel and that you have some large
data sets that you need to summarize.
Introduction xxxi
CHAPTER 4
W ith Excel 2019, Microsoft has reversed the auto date grouping added to Excel 2016. Removing the
feature was a good move, as the feature proved hard to predict. For anyone who loved the auto
grouping and the Drill-Down and Drill-Up features, you can re-create them, although it requires a few
extra steps. Grouping will be covered last in this chapter.
First, a quick overview of the PivotTable Fields. Then, a detailed look at sorting, filtering, and group-
ing a pivot table.
As you’ve seen in these pages, I rarely use the Compact form for a pivot table. I use Pivot Table
Defaults to make sure my pivot tables start in Tabular layout instead of Compact layout. Although there
are many good reasons for this, one is illustrated in Figures 4-1 and 4-2.
75
FIGURE 4-1 The drop-down menu in B3 for Customer is separate from the drop-down menu for Region.
FIGURE 4-2 In Compact form, one single drop-down menu tries to control sorting and filtering for all the row
fields.
In Figure 4-1, a Region drop-down menu appears in A3. A Customer drop-down menu appears in
B3. Each of these separate drop-downs offers great settings for sorting and filtering.
When you leave the pivot table in the Compact form, there are not separate headings for Region
and Customer. Both fields are crammed into column A, with the silly heading Row Labels. This means
the drop-down menu always offers sorting and filtering options for Region. Every time you go back to
the A3 drop-down menu with hopes of filtering or sorting the Customer field, you have to reselect Cus-
tomer from a drop-down at the top of the menu. This is an extra click. If you are making five changes
If you decide to keep the Compact layout and get frustrated with the consolidated Row Labels
drop-down menu, you can directly access the invisible drop-down menu for the correct field by using
the PivotTable Fields list, which contains a visible drop-down menu for every field in the areas at the
bottom. Those visible drop-down menus do not contain the sorting and filtering options.
The good drop-down menus are actually in the top of the Fields list, but you have to hover over the
field to see the drop-down menu appear. After you hover as shown in Figure 4-3, you can directly ac-
cess the same customer drop-down menu shown in Figure 4-1.
FIGURE 4-3 Hover over the field in the top of the Fields list to directly access the sorting and filtering settings for
that field.
After you have undocked the PivotTable Fields list, you might find that it is difficult to redock it on
either side of the screen. To redock the Fields list, you must grab the title bar and drag until at least 85%
of the Fields list is off the edge of the window. Pretend that you are trying to remove the floating Fields
list completely from the screen. Eventually, Excel gets the hint and redocks it. Note that you can dock
the PivotTable Fields list on either the right side or the left side of the screen.
FIGURE 4-4 Use this drop-down menu to rearrange the PivotTable Fields list.
The final three arrangements offered in the drop-down menu are rather confusing. If someone
changes the PivotTable Fields list to show only the Areas section, you cannot see new fields to add to
the pivot table.
If you ever encounter a version of the PivotTable Fields list with only the Areas section (see Figure
4-4) or only the Fields section, remember that you can return to a less-confusing view of the data by
using the arrangement drop-down menu.
■■ The first four choices enable you to rearrange the field within the list of fields in that area of the
pivot table. You can accomplish this by dragging the field up or down in the area.
■■ The next four choices enable you to move the field to a new area. You could also accomplish
this by dragging the field to a new area.
■■ The next choice enables you to remove the field from the pivot table. You can also accomplish
this by dragging the field outside the Fields list.
■■ The final choice displays the Field Settings dialog box for the field.
If the items do not appear in a custom list, they will be sorted in ascending order. This is fine, but in
many situations, you want the customer with the largest revenue to appear at the top of the list. When
you sort in descending order using a pivot table, you are setting up a rule that controls how that field is
sorted, even after new fields are added to the pivot table.
Tip Excel 2019 includes four custom lists by default, but you can add your own custom list
to control the sort order of future pivot tables. See the section “Using a custom list for sort-
ing,” later in this chapter.
In the second pivot table, the report is sorted in descending sequence by Total Revenue. This pivot
table was sorted by selecting cell E3 and choosing the ZA icon in the Data tab of the ribbon. Although
that sounds like a regular sort, it is better. When you sort inside a pivot table, Excel sets up a rule that
will be used after you make additional changes to the pivot table.
The pivot table in columns G:H shows what happens after you add Sector as a new outer row field.
Within each sector, the pivot table continues to sort the data in descending order by revenue. Within
Consulting, Surten Excel appears first, with $750K, followed by NetCom, with $614K.
You could remove Customer from the pivot table, do more adjustments, and then add Customer
back to the column area, and Excel would remember that the customers should be presented from
high to low.
If you could see the entire pivot table in G3:H35 in Figure 4-6, you would notice that the sectors are
sorted alphabetically. It might make more sense, though, to put the largest sectors at the top. The fol-
lowing tricks can be used for sorting an outer row field by revenue:
■■ You can select cell G4 and then use Collapse Field on the Analyze tab to hide the customer de-
tail. When you have only the sectors showing, select H4 and click ZA to sort descending. Excel
understands that you want to set up a sort rule for the Sector field.
■■ You can temporarily remove Customer from the pivot table, sort descending by revenue, and
then add Customer back.
■■ You can use More Sort Options, as described in the following paragraphs.
To sort the Sector field, you should open the drop-down menu for the Sector field. Hover over Sec-
tor in the top of the PivotTable Fields list, and click the drop-down arrow that appears (see Figure 4-7).
Or, if your pivot table is shown in Tabular layout or Outline layout, you can simply open the drop-down
arrow in cell G3.
Inside the drop-down menu, choose More Sort Options to open the Sort (Sector) dialog box. In this
dialog box, you can choose to sort the Sector field in Descending order by Total $ (see Figure 4-8).
The Sort (Sector) dialog box shown in Figure 4-8 includes a More Options button in the lower left. If
you click this button, you arrive at the More Sort Options dialog box, in which you can specify a custom
list to be used for the first key sort order. You can also specify that the sorting should be based on a
column other than Grand Total.
In Figure 4-10, the pivot table includes Product in the column area. If you wanted to sort the cus-
tomers based on total gadget revenue instead of total revenue, for example, you could do so with the
More Sort Options dialog box. Here are the steps:
4. In the More Sort Options (Customer) dialog box, choose the Sort By Values In Selected Column
option (see Figure 4-9).
5. Click in the reference box and then click cell D5. Note that you cannot click the Gadget heading
in D4; you have to choose one of the Gadget value cells.
FIGURE 4-9 Using More Sort Options, you can sort by a specific pivot field item.
If your pivot table has only one field in the Rows area, you can set up the “Sort by Doodads” rule by
doing a simple sort using the Data tab. Select any cell in B5:B30 and choose Data, ZA. The pivot table
will be sorted with the largest Doodads customers at the top (see Figure 4-10). Note that you cannot
sort from the Doodads heading in B4. Sorting from there will sort the product columns by revenue.
Note that the products in Figure 4-10 are in the following order: Doodads, Gadget, Gizmo, and
Widget. It appears that the Doodads product line is a minor product line and probably would not fall
first in the product list.
One unintended consequence is that the customers re-sort based on the product that moved to
column B: Gadget. This is because the “Sort by Doodads” rule was actually a “Sort by whatever is in
column B” rule.
In Figure 4-11, note the numbers in row 17 and compare them to the numbers in row 5 in Figure 4-10.
The values followed the change in headings.
This behavior is completely unintuitive. You should never try this behavior with a regular (non–pivot
table) data set in Excel. You would never expect Excel to change the data sequence just by moving the
labels. Figure 4-11 shows the pivot table after a new column heading has been typed in cell E4.
If you prefer to use the mouse, you can drag and drop the column heading to a new location. Select
a column heading. Hover over the edge of the active cell border until the mouse changes to a four-
headed arrow. Drag the cell to a new location, as shown in Figure 4-12. When you release the mouse, all
the value settings move to the new column.
FIGURE 4-12 Use drag and drop to move a column to a new position.
The pivot table at the top of Figure 4-13 includes weekday names. The weekday names were added
to the original data set by using =TEXT(F2,"DDD") and copying down. Excel automatically puts Sunday
first and Saturday last, even though this is not the alphabetical sequence of these words. This happens
because Excel ships with four custom lists to control the days of the week, months of the year, and the
three-letter abbreviations for both.
FIGURE 4-13 The weekday names in B4:H4 follow the order specified in the Custom Lists dialog box.
1. In an out-of-the-way section of the worksheet, type the products in their proper sequence.
Type one product per cell, going down a column.
2. Select the cells containing the list of regions in the proper sequence.
4. Select the Advanced category in the left navigation bar. Scroll down to the General group and
click the Edit Custom Lists button. In the Custom Lists dialog box, your selection address is
entered in the Import text box, as shown in Figure 4-13.
6. Click OK to close the Custom Lists dialog box, and then click OK to close the Excel Options
dialog box.
The custom list is now stored on your computer and is available for all future Excel sessions. All
future pivot tables will automatically show the product field in the order specified in the custom list.
Figure 4-14 shows a new pivot table created after the custom list was set up.
FIGURE 4-14 After you define a custom list, all future pivot tables will follow the order in the list.
To sort an existing pivot table by the newly defined custom list, follow these steps:
1. Open the Product header drop-down menu and choose More Sort Options.
3. In the More Sort Options (Product) dialog box, clear the AutoSort check box.
4. As shown in Figure 4-15, in the More Sort Options (Product) dialog box, open the First Key Sort
Order drop-down menu and select the custom list with your product names.
5. Click OK twice.
Caution Items in a custom list will automatically sort to the top of all future pivot tables.
If you have a pivot table of people using their first names, people with names like Jan, May,
and April will automatically appear before other names. Names that appear in any list,
even across several custom lists will sort in the wrong sequence. To turn off this behavior
for one pivot table: right-click one cell in the pivot table and choose PivotTable options. On
the Totals & Filters tab, unselect Use Custom Lists When Sorting. If you want to turn this off
for all pivot tables, change the Pivot Table Defaults using File, Options, Data, Edit Default
Layout, PivotTable Options.
FIGURE 4-16 This figure shows a fraction of the available filtering choices.
There are four ways to filter a pivot table, as shown in Figure 4-16:
■■ The Market filter in G12:H19 is an example of the slicer introduced in Excel 2010.
■■ A drop-down menu in B1 offers what were known as page filters in Excel 2003, report filters in
Excel 2010, and now simply filters.
■■ You see the traditional check box filters for each pivot item.
■■ Depending on the field type, you might see a Value Filters flyout menu, including the powerful
Top 10 filter, which can do Top 10, Bottom 5, Bottom 3%, Top $8 Million, and more.
■■ Depending on the field type, you might see a Date Filters flyout menu, with 37 virtual filters
such as Next Month, Last Year, and Year to Date.
If you have multiple row fields, it is just as easy to sort using the invisible drop-down menus that ap-
pear when you hover over a field in the top of the PivotTable Fields list.
The check box filter provides an easy way to hide these items. Open the Product drop-down menu
and clear the Doodads check box. The product is hidden from view (see Figure 4-17) .
FIGURE 4-17 Open the Product filter and clear the Doodads check box.
What if you need to clear hundreds of items’ check boxes in order to leave only a few items se-
lected? You can toggle all items off or on by using the Select All check box at the top of the list. You can
then select the few items that you want to show in the pivot table.
In Figure 4-18, Select All turned off all customers and then two clicks reselected Excel4Apps and
F-Keys Ltd.
The check boxes work great in this tiny data set with 26 customers. In real life, with 500 customers in
the list, it will not be this easy to filter your data set by using the check boxes.
FIGURE 4-20 For the second search, add these results to the existing filter.
You now have all customers with either Excel or spreadsheet in the name.
Caution Filters applied with the search box are single-use filters. If you add more data to
the underlying data and refresh the pivot table, this filter will not be reevaluated.
If you need to reapply the filter, it would be better to use the Label filters as discussed in the
following section. Label filters would work to find every customer with Excel in the name. It
would not work to find “Excel or spreadsheet.”
Text fields offer a flyout menu called Label Filters. To filter out all of the Insurance customers, you
can apply a Does Not Contain filter (see Figure 4-21). In the next dialog box, you can specify that you
want customers that do not contain Excel, Exc, or Exc* (see Figure 4-22).
Note that label filters are not additive. You can only apply one label filter at a time. If you take the
data in Figure 4-21 and apply a new label filter of between D and Fzzz, some Excel customers that were
filtered out in Figure 4-22 come back, as shown in Figure 4-23.
FIGURE 4-23 Note that a second label filter does not get added to the previous filter. Excel is back in.
5. Click OK.
The results are inclusive; if a customer had exactly $20,000 or exactly $30,000, they are returned
along with the customers between $20,000 and $30,000.
Note Choosing a Value filter clears out any previous Label filters.
1. Go to the Customer drop-down menu and choose Value Filters, Top 10.
2. In the Top 10 Filter dialog box, which enables you to choose Top or Bottom, leave the setting at
the default of Top.
3. In the second field, enter any number of customers: 10, 5, 7, 12, or something else.
4. In the third drop-down menu on the dialog box, select from Items, Percent, and Sum. You could
ask for the top 10 items. You could ask for the top 80% of revenue (which the theory says should
be 20% of the customers). Or you could ask for enough customers to reach a sum of $5 million
(see Figure 4-26).
The $1,758,220 total shown in cell B9 in Figure 4-26 is the revenue of only the visible customers. It
does not include the revenue for the remaining customers. You might want to show the grand total of
all customers at the bottom of the list. You have a few options:
■■ A setting on the Design tab, under the Subtotals drop-down menu, enables you to include
values from filtered items in the totals. This option is available only for OLAP data sets and data
sets where you choose Add This Data To The Data Model when creating the pivot table.
Note See Chapter 10, “Unlocking features with the Data Model and Power Pivot,” for more
information on working with Power Pivot.
■■ If you select the blank cell to the right of the last heading (C3 in Figure 4-26), you can turn on
the filter on the Data tab. This filter is not designed for pivot tables and is usually grayed out.
After you’ve added the regular filters, open the drop-down menu in B3. Choose Top 10 Filter
and ask for the top six items, as shown in Figure 4-27. This returns the top five customers and
the grand total from the data set.
Caution Be aware that this method is taking advantage of a bug in Excel. Normally, the
Filter found on the Data tab is not allowed in a pivot table. If you use this method and later
refresh the pivot table, the Excel team will not update the filter for you. As far as they know,
the option to filter is grayed out when you are in a pivot table.
FIGURE 4-27 You are taking advantage of a hole in the fabric of Excel to apply a regular AutoFilter to a pivot table.
If you choose Equals, Before, After, or Between, you can specify a date or a range of dates.
Options for the current, past, or next day, week, month, quarter, or year occupy 15 options. Com-
bined with Year To Date, these options change day after day. You can pivot a list of projects by due date
and always see the projects that are due in the next week by using this option. When you open the
workbook on another day, the report recalculates.
Tip A week runs from Sunday through Saturday. If you select Next Week, the report always
shows a period from the next Sunday through the following Saturday.
When you select All Dates In The Period, a new flyout menu offers options such as Each Month and
Each Quarter.
FIGURE 4-29 With multiple fields in the Filters area, this pivot table can answer many ad-hoc queries.
To set up the report, drag Revenue and Cost to the Values area and then drag as many fields as
desired to the Filters area.
If you add many fields to the Filters area, you might want to use one of the obscure pivot table op-
tions settings. Click Options on the Analyze tab. On the Layout & Format tab of the PivotTable Options
dialog box, change Report Filter Fields per Column from 0 to a positive number. Excel rearranges the
Filter fields into multiple columns. Figure 4-29 shows the filters with four fields per column. You can
also change Down, Then Over to Over, Then Down to rearrange the sequence of the Filter fields.
In Figure 4-30, the pivot table is filtered to show revenue from multiple sectors, but it is impossible
to tell which sectors are included.
FIGURE 4-30 You can select multiple items, but after the Filter drop-down menu closes, you cannot tell which
items were selected.
Tip Selecting multiple items from the filter leads to a situation where the person reading
the report will not know which items are included. Slicers solve this problem.
1. Make sure the formatting in the pivot table looks good before you start. You are about to make
several copies of the pivot table, and you don’t want to format each worksheet in the work-
book, so double-check the number formatting and headings now.
2. Add the Sector field to the Filters area. Leave the Sector filter set to (All).
3. Select one cell in the pivot table so that you can see the Analyze tab in the ribbon.
4. Find the Options button in the left side of the Analyze tab. Next to the Options tab is a drop-
down menu. Don’t click the big Options button. Instead, open the drop-down menu (see Figure
4-31).
5. Choose Show Report Filter Pages. In the Show Report Filter Pages dialog box, you see a list of
all the fields in the report area. Because this pivot table has only the Sector field, this is the only
choice (see Figure 4-32).
Excel inserts a new worksheet for every item in the Sector field. On the first new worksheet, Excel
chooses the first sector as the filter value for that sheet. Excel renames the worksheet to match the
sector. Figure 4-33 shows the new Consulting worksheet, with neighboring tabs that contain Museums,
Retail, Training, and Utilities.
Tip If the underlying data changes, you can refresh all of the Sector worksheets by using
Refresh on one Sector pivot table. After you refresh the Consulting worksheet, all the pivot
tables refresh.
To add slicers, click the Insert Slicer icon on the Analyze tab. Excel displays the Insert Slicers dialog
box. Choose all the fields for which you want to create graphical filters, as shown in Figure 4-34.
You can add more columns to a slicer. If you have to show 50 two-letter state abbreviations, that
will look much better as 5 rows of 10 columns than as 50 rows of 1 column. Click the slicer to get access
to the Slicer Tools Analyze tab. Use the Columns spin button to increase the number of columns in
the slicer. Use the resize handles in the slicer to make the slicer wider or shorter. To add visual interest,
choose a different color from the Slicer Styles gallery for each field.
After formatting the slicers, arrange them in a blank section of the worksheet, as shown in Figure 4-36.
FIGURE 4-36 After formatting, your slicers might fit on a single screen.
Note that you can control the heading for the slicer and the order of items in the slicer by using the
Slicer Settings icon on the Slicer Tools Options tab of the ribbon. Just as you can define a new pivot
table style, you can also right-click an existing slicer style and choose Duplicate. You can change the
font, colors, and so on.
A new icon debuted in Excel 2016, in the top bar of the slicer. The icon appears as three check marks.
When you select this icon, you can select multiple items from the slicer without having to hold down
the Ctrl key.
For Excel 2013, Microsoft introduced a new kind of filter called a Timeline slicer. To use one, select
one cell in your pivot table and choose Insert Timeline from the Analyze tab. Timeline slicers can only
apply to fields that contain dates. Excel gives you a list of date fields to choose from, although in most
cases, there is only one date field from which to choose.
Figure 4-38 shows a Timeline slicer. Perhaps the best part of a Timeline slicer is the drop-down
menu that lets you repurpose the timeline for days, months, quarters, or years. This works even if you
have not grouped your daily dates up to months, quarters, or years.
Now, one set of slicers or timelines can be used to drive multiple pivot tables or pivot charts. In Fig-
ure 4-39, the Market slicer is driving three elements. It drives the pivot table in the top left with revenue
by sector and product. It drives two pivot tables created for the top-right and lower-left charts.
The following steps show you how to create three pivot tables that are tied to a single slicer:
2. Select a cell in the first pivot table. Choose Insert Slicer. Choose one or more fields to be used as
a slicer. Alternatively, insert a Timeline slicer for a date field.
6. Paste. Excel creates a second pivot table that shares the pivot cache with the first pivot table. In
order for one slicer to run multiple pivot tables, they must share the same pivot cache.
7. Change the fields in the second pivot table to show some other interesting analysis.
The preceding steps require you to create the slicer after you create the first pivot table but before
you make copies of the pivot table.
If you already have several existing pivot tables and need to hook them up to the same slicer, follow
these steps:
1. Click the slicer to select it. When the slicer is selected, the Slicer Tools Design tab of the ribbon
appears.
2. Select the Slicer Tools Design tab and choose Report Connections. Excel displays the Report
Connections (Market) dialog box. Initially, only the first pivot table is selected.
3. As shown in Figure 4-40, choose the other pivot tables in the dialog box and click OK.
FIGURE 4-40 Choose to hook this slicer up to the other pivot tables.
4. If you created multiple slicers and/or timelines, repeat steps 1 through 3 for the other slicers.
FIGURE 4-41 All of the pivot charts and pivot tables update when you choose from the slicer.
Tip The worksheet in Figure 4-41 would be a perfect worksheet to publish to SharePoint
or to your OneDrive. You can share the workbook with coworkers and allow them to interact
with the slicers. They won’t need to worry about the underlying data or enter any numbers;
they can just click on the slicer to see the reports update.
You can use the Power Pivot grid to define a hierarchy so you can quickly drill down on a pivot table or
chart.
FIGURE 4-42 Nothing interesting here—just lots of order totals that appear exactly one time in the database.
Select one number in column A of the pivot table. Select Group Field from the Analyze tab of the
ribbon. Because this field is not a date field, the Grouping dialog box offers fields for Starting At, End-
ing At, and By. As shown in Figure 4-43, you can choose to show amounts from 0 to 30,000 in groups of
5,000.
FIGURE 4-43 Create a frequency distribution by grouping the order size into $5,000 buckets.
After grouping the order size into buckets, you might want to add additional fields, such as Revenue
and % Of Revenue shown as a percentage of the total.
Note The grouping dialog box requires all groups to be the same size. I have heard ques-
tions where people want to group into 0–100K, 200K–500K, but this is not possible using the
Grouping feature. You would have to add a new column to the source data in order to create
these groupings.
FIGURE 4-44 Use the Ctrl key to select the noncontiguous cells that make up the new region.
From the Analyze tab, click Group Selection. Excel adds a new field called Market2. The five
selected regions are arbitrarily rolled up to a new territory called Group1. In Figure 4.45, the
Group1 label in A4 is the first item in the new Market2 virtual field. The other items in the
Market2 field includee Atlanta in A10, Charlotte in A12 and so on. The similar items in A11 and
A13 are items in the original Market field. Use care while holding down the Ctrl key to select
the unbolded markets for the South region: Atlanta in row 11, Charlotte in row 13, Huntsville
in row 11, and Louisville in row 23...
Click Group Selection to group the markets in the proposed Southeast region. Repeat to
group the remaining regions into the proposed Northeast region. Figure 4-46 shows what
it looks like when you have grouped the markets into new regions. Five things need further
FIGURE 4-46 The markets are grouped, but you have to do some cleanup.
2. Select cell A10. Type Southeast to replace the arbitrary name Group2.
4. Select any outer heading in A4, A10, or A15. Click Field Settings on the Analyze tab.
5. In the Field Settings dialog box, replace the Custom Name of Market2 with Proposed
Region. Also, in the Field Settings dialog box, change the Subtotals setting from None
to Automatic.
Figure 4-47 shows the pivot table that results, which is ready for the VP of Sales.
FIGURE 4-47 It is now easy to see that these regions are heavily unbalanced.
You can probably predict that the Sales Department needs to shuffle markets to balance the
regions. To go back to the original regions, select any Proposed Region cell in A4, A10, or
A15 and choose Ungroup. You can then start over, grouping regions in new combinations.
When your field contains date information, the date version of the Grouping dialog box appears. By
default, the Months option is selected. You have choices to group by Seconds, Minutes, Hours, Days,
Months, Quarters, and Years. It is possible—and usually advisable—to select more than one field in the
Grouping dialog box. In this case, select Months and Years, as shown in Figure 4-48.
There are several interesting points to note about the resulting pivot table. First, notice that the
Years field has been added to the PivotTable Fields list. Don’t let this fool you. Your source data is not
changed to include the new field. Instead, this field is now part of your pivot cache in memory.
Another interesting point is that, by default, the Years field is automatically added to the same area
as the original date field in the pivot table layout, as shown in Figure 4-49. Although this happens au-
tomatically, you are free to pivot months and years onto the opposite axis of the report. This is a quick
way to create a year-over-year sales report.
FIGURE 4-49 By default, Excel adds the new grouped date field to your pivot table layout.
FIGURE 4-50 If you fail to include the Year field in the grouping, the report mixes sales from last January and this
January into a single row called January.
The first step is to find either a paper calendar or an electronic calendar, such as the Calendar fea-
ture in Outlook, for the year in question. If your data starts on January 1, 2024, it is helpful to know that
January 1 is a Monday that year. You need to decide if weeks should start on Sunday or Monday or any
other day. For example, you can check the paper or electronic calendar to learn that the nearest start-
ing Sunday is December 31, 2023.
Select any date heading in your pivot table. Then select Group Field from the Analyze tab. In the
Grouping dialog box, clear all the By options and select only the Days field. This enables the spin but-
ton for Number of Days. To produce a report by week, increase the number of days from 1 to 7.
Next, you need to set up the Starting At date. If you were to accept the default of starting at Janu-
ary 1, 2024, all your weekly periods would run from Monday through Sunday. By checking a calendar
before you begin, you know that you want the first group to start on December 31, 2023, to have weeks
that run Sunday through Monday. Figure 4-51 shows the settings in the Grouping dialog box and the
resulting report.
Number of days
Caution If you choose to group by week, none of the other grouping options can be se-
lected. You cannot group this or any field by month, quarter, or year. You cannot add calcu-
lated items to the pivot table.
The feature was turned on by default, and the only way to turn it off was a change in the Registry.
I love the concept of teaching people that daily dates can easily be rolled up. But for the people who
needed to report daily dates, the AutoGroup was inconsistent and confusing. The logic used to choose
which rollups would be present would sometimes leave out daily dates from the hierarchy.
Today, Excel 2019 will not automatically AutoGroup. You can choose to allow the AutoGroup if you
loved this feature. Go To File, Options, Data, and deselect Disable Automatic Grouping Of Date/Time
Columns In Pivot Tables.
Caution If your company is closed on New Year’s Day and you have no sales on January 1,
a data set that stretches from January 2 to December 31 will fit the “less than a full year” case
and will include months and daily dates.
If your data contains times that do not cross over midnight, you get hours, minutes, and seconds. If
the times span more than one day, you get days, hours, minutes, and seconds.
Using AutoGroup
Say that you have a column in your data set with daily dates that span two years. When you add this
Date field to the Rows area of your pivot table, you will see rows for each year instead of hundreds of
daily dates. If your pivot table is in Tabular layout, you will see extra columns for Quarter and Date that
appear to have no data (see Figure 4-52).
When you look in the Pivot Table Fields list, you see that the Rows area automatically includes three
fields: Years, Quarter, and Date. All three of these are virtual fields created by grouping the daily dates
up to months, quarters, and years.
The three fields are added to either the Rows area or the Columns area. However, only the highest
level of the date field will be showing. To see the quarters and years, click one cell that contains a year
and then click the Expand button in the Analyze tab of the ribbon (see Figure 4-53). To see months,
select a cell containing a quarter and click the Expand button again (see Figure 4-54).
FIGURE 4-52 Excel can automatically groups two years’ worth of daily dates up to months, quarters, and years
1. Create a pivot table with Years in the Columns area and Months in the Rows area. Drag Revenue
to the Values area. By default, the pivot table will offer a Grand Total column, as shown in Figure
4-55.
2. Right-click the Grand Total heading and choose Remove Grand Total.
4. In the Columns area, drag Years so it is below Values. You will have the pivot table shown in
Figure 4-56.
FIGURE 4-56 This year and last year appear twice across the top of the report.
5. Double-click the Sum of Revenue2 heading in cell D4 to display the Value Field Settings dialog
box.
6. In the Value Field Settings dialog box, select the Show Values As tab. In the Show Values As
drop-down menu, choose % Difference From. In the Base Field list, choose Years. In the Base
Item, choose (Previous), as shown in Figure 4-57.
7. Close the Value Field Settings dialog box. Column E will show the percentage change from the
first year to the last year. Column D will be blank because the pivot table has no data from 2023
to use to compare to 2024.
8. Hide column D.
9. Select the 2025 heading in E5. Press Ctrl+1 for Format Cells. On the Number tab, choose Cus-
tom. Type a format of ;;;"% Change".
You have a report showing year 1 versus year 2 and a percentage change. You can easily remove the
Months from column A and insert Region, Market, or Product to see the year-over-year change. Figure
4-58 shows a year-over-year report for Regions.
FIGURE 4-58 Once you have the year-over-year report set up, you can swap any field in to column A.
Consider the pivot table and pivot chart shown in Figure 4-59. The pivot table is built using the Data
Model; when you choose Insert Pivot Table, make sure to choose Add This Data To The Data Model. The
pivot table has regions in the Rows area and Products in the Columns area. The pivot chart is showing a
stacked column chart.
FIGURE 4-59 A pivot table and a pivot chart without any hierarchy.
1. Click the Manage icon in the Power Pivot tab of the ribbon.
2. On the Home tab of the Power Pivot for Excel window, click Diagram View.
3. Resize the Range table so you can see all the fields.
4. Click on the top field for the hierarchy: Region. Ctrl+click the remaining members of the hierar-
chy: Market and Rep.
6. Hierarchy1 will appear at the bottom of the table. Right-click the name and choose Rename.
Type a meaningful name such as Geography (see Figure 4-61).
7. Carefully review the sequence of the hierarchy. In Figure 4-61, Rep is appearing before Market.
This is incorrect. Right-click on Market and choose Move Up.
8. Close the Power Pivot window and return to Excel. After a brief pause, the PivotTable Fields list
will show the table name (Range), the hierarchy name (Geography), and something called More
Fields.
FIGURE 4-62 Plus signs appear next to each region. The Drill Down icon is enabled.
10. Select cell A7 for South. Click on Drill Down. The pivot table and pivot chart will change to show
the markets in the South region (see Figure 4-63).
You can keep using Drill Down or Drill Up to travel through the hierarchy.
Next steps
In Chapter 5, “Performing calculations in pivot tables,” you’ll learn how to use pivot table formulas to
add new virtual fields to a pivot table.
443
3D Map
B
396-398
to data areas, 332-333
to reports, 22-24 backward compatibility
functionality to recorded macros, 308-309 Check Compatibility tool, 7-9
layers to reports, 25 pivot tables and Excel, 7-8
Timeline slicer, 35
444
calculations
445
calculations
446
columns
With and End With, 329 renaming columns with Power Pivot, 287
Collie, Rob, 143, 287, 425, 432 sorting one column by another with
Power Pivot, 282
447
columns
448
customizing
449
customizing
D relationships
activating, 180
Dalgleish, Debra, 45 creating, 178-180
data areas creating between tables, 382
blank cells, filling in data areas, 336 deactivating, 180
fields, adding to, 332-333 deleting, 180
data cards (tooltips), 3D Map, 296 editing, 180
data items, sorting in a unique sort order, managing, 179
389-390
tables
Data Model, 330
adding linked tables to Data Model, 279
32-bit Excel and, 287
adding to Data Model, 180, 381
adding
creating relationships, 382
linked tables to Data Model, 279
defining relationships between tables,
model fields to pivot tables, 383 279-280
numeric fields to Values area, 384 text, reporting in Values area, 272
tables to Data Model, 279, 381 Values area, reporting text in, 272
creating, 176-179 VLOOKUP functions, replacing with Data
cube formulas, converting pivot tables to, Model, 261-266
232-238 data ranges
DAX measures and median calculations, automatically expanding data ranges,
269-271 creating, 399
Distinct Count, 266-267 writing code for, 327-328
Filtered Items in Totals, 269 data sets
limitations of, 180, 286-287 combining in 3D Map, 297
loading to Data Model instead of Excel grid, exploding
277-278
to different tabs in pivot tables, 410-411
median calculations with DAX measures,
to different workbooks, 415-417
269-271
transposing with Power Query (case study),
202-204
450
documenting
451
Doodads rule
Doodads rule, Sort by, 82-83 Excel grid, loading to Data Model instead,
dragging/dropping fields in reports, 25-26 277-278
drill-down methods, 286 Excel Help tool (VBA), 326
exploding data sets
to different tabs, 410-411
E to workbooks, 415-417
external data
editing defined, 175
calculations, 146, 147 pivot tables, creating, 181
Data Model relationships, 180 from Access (MS) data, 181-184
empty cells filling in row fields, 393 from SQL Server data, 184-187
Go To Special function (Excel), 395-396 extracting cells from pivot tables based on pivot
Repeat All Item Labels feature, 394-395 caches, 232
empty columns in data sources, 14 extracts, creating, 3
empty rows in data sources, 14
End+Down arrow versus End+Up arrow, coding,
328
End With and With, coding, 329
F
erasing pivot table layouts, 40 February 29 1900 and Power Pivot, 286-287
Escobar, Miguel, 287 Field list, Areas section drop-downs, 78-79
ETL (Extraction, Transformation, Loading) fields
processes, 188 adding to reports, 22-24
“evil GetPivotData problem”, 426-428 calculated fields, 286, 358-359
Excel creating, 123-128
32-bit Excel defined, 121
Data Model and, 287 inserting into pivot tables, 124-125
Power Pivot and, 287 manually adding to data sources,
Go To Special function, filling empty cells in 122-123
row fields, 395-396 rules specific to, 139-140
pivot tables, backward compatibility, 7, 8 summarizing next year’s forecast (case
versions of, 330 study), 129-133
Excel 2019 using DAX measures instead of cal-
Office 365 versus, xxix-xxx culated fields (case study), 141-145
recommended pivot tables, xxvii changing names, 49
ribbon, xxix-xxx collapsing/expanding in Compact layouts, 51
system requirements, xxxii column fields
Excel 2019 In Depth, 306 adding multiple subtotals to one field, 72
filtering, 88
452
filters
453
filters
454
Insights feature and Power BI Desktop
preventing
by turning off GetPivotData, 429-430
H
by typing the formula, 429 hard data, turning pivot tables into, 393
problems with, 426-428 headings
GETPIVOTDATA function column headings, 11
cube formulas versus, 232 section headings, storing data in, 12
extracting cells from pivot tables based on heat maps in 3D Map, 294
pivot caches, 232 help
Get & Transform tools, cleaning up data sources Excel Help tool (VBA), 326
(case studies), 15-19 support/feedback, xxxii
globes, using store maps instead of (case study), hiding
299-302 columns with Power Pivot, 287
Go To Special function (Excel), empty cells, filling legends in 3D Map, 296
in row fields, 395-396 panes in 3D Map, 296
grand totals hierarchies, 116-118
calculations, grand total references, 139 drill-down hierarchies, 219-220
controlling with VBA, 337-338 OLAP cubes, 243, 257
layouts, 50, 57-58 Power Pivot and, 287
gridlines, restoring to pivot tables, 45 high-to-low sequences, sorting customers in
grouping based on revenue, 79-82
auto date-grouping, 75 Hoter, Dany, 238
AutoGroup
determining AutoGroup criteria, 111
using, 112
year-over-year reports, 113-115
I
calculating groups, 361-362 Ideas feature, 29-30
date fields images in Power BI Desktop, 212
by week, 110-111 importing
including years when grouping by custom visualizations, Power BI Desktop,
months, 110 221-222
manually grouping, 108-109 data to Power BI Desktop, 208
date grouping, xxiv Index option (Value Field Settings dialog box,
numeric fields, 104-105 Show Values As tab), 69-70
pivot tables, 286 individual values, formatting in pivot tables,
repeating as columns, 13 405-407
text fields for redistricting (case study), Insert Slicers dialog box, 31-32
106-108 Insights command (Office 365), xxiv
Insights feature and Power BI Desktop, 224
455
interactive reports
456
measures (DAX)
457
measures (DAX)
N ribbon, xxx
offline cubes, creating, 245-247
named ranges and calculations, 139 OLAP (Online Analytical Processing)
named sets, 330 cubes
naming connecting to, 239-242
fields, 49 dimensions of, 243
pivot tables, 33 functions, 248-250
natural language queries and Power BI Desktop, hierarchies of, 243, 257
213 levels of, 243
navigating maps in 3D Map, 292-293 measures of, 243, 250-253
next year’s forecast (case study), summarizing, members of, 243, 250, 254-257
129-133
offline cubes, creating, 245-247
number fields (rank), adding to pivot tables,
PivotTable Fields list, 244
396-398
structure of, 242-243
number formats
databases, 239-240, 250-251
changing in pivot tables, 347-348
pivot tables
multiple formats in pivot tables, 404-405
adding calculations to, 250
thousands separators, 46-47
limitations of, 244-245
458
pivot table reports
P x-axis, 155
on pivot charts, 154-156
459
pivot tables
460
pivot tables
461
pivot tables
all pivot tables in a workbook at the creating reports for each region/model,
same time, 388 369-373
automatically refreshing, 388 creating revenue by category reports,
relocating, 41 341-344
restrictions, 412-413 date filters, 375
Rows area, 5, 22 date groups, 344-346
slicers deleting blank cells, 346-347
connecting to multiple pivot tables, filtering recordsets with ShowDetail,
32-33 367-373
standard slicers, 31-33 formatting pivot tables, 350
Timeline slicer, 34-35 label filters, 374
sort order, controlling with AutoSort, 347 manually filtering multiple items in pivot
sorting fields, 373-374
custom lists, 390-391 search filter, 377-378
unique sort order, 389-390 slicers, filtering pivot tables, 378-380
static values (case study), converting live subtotals as page breaks, 350-351
tables to, 54-55 summary reports, producing, 352-354
subtotals suppressing subtotals for multiple row
as page breaks, 350-351 fields, 348
suppressing for multiple row fields, 348 Tabular layouts, 344
Tabular layouts and VBA, 344 value filters, 375
ugly pivot tables, creating, 432-435 versions of, 330
updates, xxxii workbooks, copying pivot tables to, 349-350
usage examples, 2, 3 Power BI Custom Visuals, 173-174
Values area, 4, 22 Power BI Desktop, xxiv, 207
VBA cross-filtering charts, 218
AutoShow and executive overviews, drill-down hierarchies, 219-220
365-367 Excel, preparing data in, 208
calculating with pivot tables, 355-364 images in, 212
changing default number format, importing data to, 208
347-348 Insights feature, 224
conceptual filters, 374-377 interactive reports, creating
controlling sort order with AutoSort, 347 creating visualizations, 213-217
converting to values, 338-341 cross-filtering charts, 218
copying as values to workbooks, designing reports for mobile phones,
349-350 223
creating pivot tables, 330-338 drill-down hierarchies, 219-220
462
Power Query
463
Power Query
464
reports
465
reports
466
store maps
467
store maps
468
VBA (Visual Basic for Applications)
two-way VLOOKUP, 419-424 Index option (Value Field Settings dialog box,
Show Values As tab), 69-70
line-to-line comparisons, 66
469
VBA (Visual Basic for Applications)
470
workbooks
471
worksheets
worksheets
functions and calculations, 139
Y
source data worksheets, deleting, 398 y-axis (pivot charts), 155
workspaces, publishing interactive reports to, year-over-year reports
223-224 creating, 113-115
percentage change column and, 417-419
years
472