MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Top Five Report


August 08, 2017 - by Bill Jelen

Top Five Report

The pivot table Top 10 Filter gives a total of the visible rows

Pivot tables offer a Top 10 filter. It is cool. It is flexible. But I hate it, and I will tell you why.

Here is a pivot table showing revenue by customer. The revenue total is $6.7 million.

Sample Pivot Table
Sample Pivot Table

What if my manager has the attention span of a goldfish and wants to see only the top five customers?

To start, open the dropdown in A3 and select Value Filters, Top 10.

Value Filters
Value Filters

The super-flexible Top 10 Filter dialog allows Top/Bottom. It can do 10, 5, or any other number. You can ask for the top five items, top 80%, or enough customers to get to $5 million.

Top 10 Filter
Top 10 Filter

But here is the problem: The resulting report shows five customers and the total from those customers instead of the totals from everyone.

Grand Total
Grand Total

But First, a Few Important Words About AutoFilter

I realize this seems like an off-the-wall question. If you want to turn on the Filter dropdowns on a regular data set, how do you do it? Here are three really common ways:

  • Select one cell in your data and click the Filter icon on the Data tab.
  • Select all of your data with Ctrl + * and click the Filter icon on the Data tab.
  • Press Ctrl + T to format the data as a table.

These are three really good ways. As long as you know any of them, there is absolutely no need to know another way. But here's an incredibly obscure but magical way to turn on the filter:

  • Go to your row of headers, go to the rightmost heading cell. Move one cell to the right. For some unknown reason, when you are in this cell and click the Filter icon, Excel filters the data set to your left. I have no idea why this works. It really isn’t worth talking about because there are already three really good ways to turn on the Filter dropdowns. I call this cell the Magic cell.

And now, Back to Pivot Tables...

So, there is a rule that says you cannot use the AutoFilters when you are in a pivot table. See below? The Filter icon is grayed out because I’ve selected a cell in the pivot table.

Filter is Disabled in Pivot Table
Filter is Disabled in Pivot Table

I never really considered why Microsoft grays this out. It must be something internal that says AutoFilter and a Pivot Table can’t coexist. So, there is someone on the Excel team who is in charge of graying out the Filter icon. That person has never heard of the Magic cell. Select a cell in the pivot table, and the Filter gets grayed out. Click outside of the pivot table, and Filter is enabled again.

But wait. What about the Magic cell I just told you about? If you click in the cell to the right of the last heading, Excel forgets to gray out the Filter icon!

Filter is Enabled for Magic Cell
Filter is Enabled for Magic Cell
Illustration: George Berlin
Illustration: George Berlin

Sure enough, Excel adds AutoFilter dropdowns to the top row of your pivot table. And the AutoFilter operates differently than pivot table filters. Go to the Revenue dropdown and choose Number Filters, Top 10...

alt
Number Filters - Top 10

In the Top 10 AutoFilter dialog, choose Top 6 Items. That’s not a typo…. If you want five customers, choose 6. If you want 10 customers, choose 11.

Top 10 Autofilter Dialog
Top 10 Autofilter Dialog

To AutoFilter, the grand total row is the largest item in the data. The top five customers are occupying positions 2 through 6 in the data.

Top Five Customers
Top Five Customers

Caution

Clearly, you are tearing a hole in the fabric of Excel with this trick. If you later change the underlying data and refresh your pivot table, Excel will not refresh the filter, because, as far as Microsoft knows, there is no way to apply a filter to a pivot table!

Note

Our goal is to keep this a secret from Microsoft, because it is a pretty cool feature. It has been “broken” for quite some time, so there are a lot of people who might be relying on it by now. 

A Completely Legal Solution in Excel 2013+

If you want a pivot table showing you the top five customers but the total from all customers, you have to move your data outside of Excel. If you have Excel 2013 or 2016, there is a very convenient way to do this. To show you this, I’ve deleted the original pivot table. Choose Insert, Pivot Table. Before clicking OK, select the box that says Add This Data to the Data Model.

Add his Data to the Data Model
Add his Data to the Data Model

Build your pivot table as normal. Use the dropdown in A3 to select Value Filters, Top 10, and ask for the top five customers. With one cell in the pivot table selected, go to the Design tab in the ribbon and open the Subtotals dropdown. The final choice in the dropdown is Include Filtered Items in Totals. Normally, this choice is grayed out. But because the data is stored in the Data Model instead of a normal pivot cache, this option is now available.

Include Filtered Items in Totals
Include Filtered Items in Totals

Choose the Include Filtered Items in Total option, and your Grand Total now includes an asterisk and the total of all of the data.

Grand Total with Asterisk
Grand Total with Asterisk

This trick originally came to me from Dan in my seminar in Philadelphia. Thanks to Miguel Caballero for suggesting this feature.

Watch Video

  • The pivot table Top 10 Filter gives a total of the visible rows
  • Include Filtered Items in Totals is Greyed Out
  • Odd way to invoke the Data Filter from the magic cell
  • Data Filters are not allowed in pivot tables
  • Excel fails to grey out the Data Filter from the magic cell
  • Ask for the top 6 to get top 5 plus Grand Total
  • Useful for filtering by a specific pivot item
  • Excel 2013 or newer: Different Way to get the True Total
  • Send your data through the Data Model
  • Include Filtered Items in Totals will be available
  • Get Total with asterisk
  • I learned this trick 10+ years ago from Dan in Philadelphia

Download File

Download the sample file here: Podcast1999.xlsx

Title Photo: Gadini / pixabay