How to Rank with a Pivot Table
In this article
Ranking data inside a pivot table lets you instantly see who or what is at the top of your list—top sales reps, best-selling products, highest-scoring students—without writing complex formulas or manually sorting. This guide shows you how to add a rank column to any pivot table in Microsoft Excel or Google Sheets, using built-in features and simple calculated fields.
What You'll Need
- A dataset with at least one numeric field (e.g., sales, scores, quantities) and a category field (e.g., names, products, regions).
- Access to Microsoft Excel (2016 or later) or Google Sheets.
- Basic familiarity with creating a pivot table (selecting data, choosing rows and values).
Step-by-Step
- Create your pivot table – Select your data range, go to Insert > PivotTable (Excel) or Data > Pivot table (Sheets). Drag the category field (e.g., “Salesperson”) to the Rows area and the numeric field (e.g., “Revenue”) to the Values area. Ensure the value is summarized correctly (Sum, Count, Average, etc.).
- Sort the pivot table – Click the drop-down arrow next to the row label (or the value header) and choose Sort Largest to Smallest (descending) if you want the highest value to be rank 1. This step is optional but makes the rank column easier to read.
- Add a rank field (Excel only) – In Excel, go to the PivotTable Analyze tab (or right-click the pivot table and choose PivotTable Options). Click Fields, Items & Sets > Calculated Field. Name it “Rank” and enter the formula:
=GETPIVOTDATA("Revenue",$A$3,"Salesperson","Salesperson")– but this is a manual workaround. A simpler method is to use the Value Field Settings on a copy of the value field. - Copy the value field – Drag the same numeric field (e.g., “Revenue”) into the Values area again. You will now have two columns: “Sum of Revenue” and “Sum of Revenue2”.
- Change the second field to a rank – Right-click the second value field (e.g., “Sum of Revenue2”) and choose Show Values As > Rank Largest to Smallest (Excel). In Google Sheets, this option is not built-in; use the RANK function in a helper column instead (see Tips).
- Adjust the rank base – In Excel, after selecting “Rank Largest to Smallest”, you can set the base field. By default, it ranks across the whole table. If you have multiple row fields (e.g., Year and Salesperson), you can choose “Salesperson” as the base field to rank within each year.
- Rename the rank column – Click the header cell (e.g., “Sum of Revenue2”) and rename it to “Rank” for clarity.
- Format the rank column – Right-click the rank cells, choose Number Format, and select a number format without decimals (e.g., “0”) to display clean integers.
- Refresh data – If your source data changes, right-click the pivot table and choose Refresh (Excel) or click the refresh icon in Sheets. The ranks will update automatically.
Common Mistakes
- Ranking the wrong value – If you have multiple value fields, make sure you are ranking the correct one. The rank option is applied to the specific value field you right-click.
- Forgetting to refresh – Pivot tables do not automatically update when source data changes. Always refresh to get accurate ranks.
- Using a calculated field for ranking – Calculated fields cannot reference the pivot table’s own totals directly, so they often produce errors or incorrect ranks. Use the “Show Values As” method instead.
- Ranking with ties – Excel’s default rank assigns different ranks to tied values (e.g., 1, 2, 2, 4). If you want tied values to share the same rank, you’ll need a custom formula outside the pivot table.
- Assuming Google Sheets has the same option – Google Sheets does not have “Show Values As > Rank”. You must use a helper column with the RANK function.
Tips
- Use a helper column in Google Sheets – After creating your pivot table, add a column next to it and use the formula
=RANK(C2,$C$2:$C$10,0)(adjust ranges) to rank the values in the pivot table’s value column. This is a simple workaround. - Rank within groups – If you have multiple row fields, use the “Base Field” option in Excel’s “Show Values As” to rank within each group (e.g., rank products within each region).
- Create a top 10 list – Use a Value Filter on the row labels (e.g., “Top 10”) to show only the top-ranked items. This works well with the rank column.
- Sort by rank – If you don’t sort the pivot table first, the rank column will still show correct numbers, but the rows may be in a different order. Sort by the rank column to see the list from 1 to N.
- Use conditional formatting – Highlight the rank column to visually identify the top 3 (e.g., use a color scale or icon set).
Troubleshooting
- “Show Values As” is greyed out – This happens when you right-click a row or column label instead of a value field. Make sure you right-click directly on a value cell (e.g., a number in the Sum of Revenue column).
- Rank column shows #DIV/0! error – This can occur if the pivot table has empty cells or if the base field is set incorrectly. Check that your source data has no blank values in the numeric field, and try changing the base field to “(previous)” or the specific row field.
- Ranks do not update after changing data – Refresh the pivot table manually (right-click > Refresh). If that fails, close and reopen the file.
- Google Sheets: RANK formula gives wrong results – Ensure the range in the RANK function matches the exact cells of the pivot table’s value column. If you add or remove rows, update the range.
- Rank order is reversed – If you want the smallest value to be rank 1, use “Rank Smallest to Largest” in Excel, or change the order parameter in RANK (use 1 instead of 0) in Sheets.
Frequently Asked Questions
Can I rank in a pivot table without a calculated field?
Yes. In Excel, use “Show Values As” > “Rank Largest to Smallest” on a duplicate value field. In Google Sheets, use a helper column with the RANK function.
How do I rank within groups (e.g., by region)?
In Excel, after applying “Rank Largest to Smallest”, click the field and choose “Base Field” and select the group field (e.g., Region). In Sheets, use the QUERY or SORT functions to create a ranked list per group.
Does ranking work with text values?
No. Ranking requires numeric values. If you have text, you can assign a numeric score or use COUNTIF to create a rank based on frequency.
Why does my rank column show decimals?
Excel may format the rank as a decimal if the original value field had decimals. Change the number format of the rank cells to “0” or “General”.
Can I rank using multiple criteria (e.g., same sales, then higher profit)?
Excel’s built-in rank does not handle tie-breakers. You can add a second value field (e.g., profit) and rank that as a tie-breaker, or use a custom formula outside the pivot table.
Will the rank update automatically when I add new data?
Only after you refresh the pivot table. If you add rows to the source data, expand the data range in the pivot table settings, then refresh.