# Excel 2019: Find the True Top Five in a Pivot Table

May 09, 2019 - by Bill Jelen

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 that shows revenue by customer. The revenue total is \$6.7 million. Notice that the largest customer, Roto-Rooter, is 9% of the total revenue.

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.

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.

But here is the problem: The resulting report shows five customers and the total from those customers instead of the totals from everyone. Roto-Rooter, who was previously 9% of the total is 23% of the new 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 or press Ctrl+Shift+L.
• 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 and then 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

There is a rule that says you cannot use AutoFilter 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.

I don't know 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 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!

Sure enough, Excel adds AutoFilter dropdowns to the top row of your pivot table. And AutoFilter operates differently than a pivot table filter. Go to the Revenue dropdown and choose 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.

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.

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 Excel. If you have Excel 2013 or newer running in Windows, 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 checkbox Add This 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.

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

This magic cell trick originally came to me from Dan in my seminar in Philadelphia and was repeated 15 years later by a different Dan from my seminar in Cincinnati. Thanks to Miguel Caballero for suggesting this feature.

Title Photo: Zhu Hongzhi at Unsplash.com

##### Bill Jelen is the author / co-author ofExcel Dynamic Arrays Straight to the Point 2nd Edition

Fifteen months after Dynamic Arrays debuted for Office Insiders, the functions are being released to General Availability. This second edition of the book has been updated with new examples: see how Dynamic Arrays make XLOOKUP better. The chapter on the logic behind arrays has been expanded.