How-to recipes · Analysis
How to list the top 5 values with names in Excel
Build a top 5 list with names and values using TAKE and SORT in Microsoft 365, or LARGE with INDEX and MATCH in older Excel, and handle ties.
Dashboards and monthly reports often start with a leaderboard: the five best-selling products, the top five sales reps, the five largest customers. Finding the five largest numbers is easy with LARGE; the challenge is bringing the matching names along, keeping the list up to date as data changes, and dealing with two people who have exactly the same value. This recipe shows a one-formula solution for Microsoft 365 and a reliable approach for Excel 2016 and 2019.
The example data
Eight sales reps with their annual sales in A1:B9.
Microsoft 365: TAKE + SORT
SORT sorts the whole table by the second column in descending order, and TAKE keeps the first five rows:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Rep | Sales | |||
| 2 | Ana | 48200 | Chloe | 52700 | |
| 3 | Ben | 39500 | Ana | 48200 | |
| 4 | Chloe | 52700 | Hana | 46900 | |
| 5 | Dev | 31800 | Eva | 44100 | |
| 6 | Eva | 44100 | Ben | 39500 | |
| 7 | Femi | 36500 | |||
| 8 | Gus | 27600 | |||
| 9 | Hana | 46900 |
Names and values spill together into D2:E6.
SORT(A2:B9,2,-1): sort by column 2 (Sales),-1for largest first.TAKE(...,5): keep the first 5 rows. Change it to-5on an ascending sort for the bottom five.- The list updates as soon as a sales figure changes.
If you have Excel 2021 without TAKE, use INDEX with a row sequence instead: =INDEX(SORT(A2:B9,2,-1),SEQUENCE(5),{1,2}). Make the number of rows a cell reference (for example TAKE(...,G1)) to let users choose a top 3 or top 10.
Including ties at the cut-off
If the 5th and 6th reps had the same sales, TAKE would show only one of them. To include everyone who reaches the 5th-highest value, filter instead of cutting: =SORT(FILTER(A2:B9,B2:B9>=LARGE(B2:B9,5)),2,-1). The list may then contain six or more rows, which is the fair result for a leaderboard.
Excel 2016 and 2019: LARGE + INDEX/MATCH
Put the numbers 1 to 5 in D2:D6. In F2 get the n-th largest value, and in E2 find the name that belongs to it:
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Rep | Sales | Top | Name | Sales | |
| 2 | Ana | 48200 | 1 | Chloe | ||
| 3 | Ben | 39500 | 2 | |||
| 4 | Chloe | 52700 | 3 | |||
| 5 | Dev | 31800 | 4 | |||
| 6 | Eva | 44100 | 5 | |||
| 7 | Femi | 36500 | ||||
| 8 | Gus | 27600 | ||||
| 9 | Hana | 46900 |
LARGE returns 52700, MATCH finds it in row 3 of the list, INDEX returns the name. F2 holds =LARGE($B$2:$B$9,D2).
Result: Chloe
Copy E2:F2 down to row 6 and the table shows Chloe, Ana, Hana, Eva, Ben. Instead of typing 1 to 5, you can use ROWS($D$2:D2) inside LARGE, which counts 1, 2, 3 as the formula is copied down.
The duplicate-name problem
MATCH always finds the first row with a value. If two reps both had 39500, LARGE would correctly return 39500 twice, but MATCH would return the same name both times. The fix is to look for the k-th row whose value is equal to or greater than the current one with AGGREGATE:
=INDEX($A$2:$A$9,AGGREGATE(15,6,(ROW($B$2:$B$9)-ROW($B$2)+1)/($B$2:$B$9=F2),COUNTIF($F$2:F2,F2)))COUNTIF($F$2:F2,F2) counts how many times this value has already appeared in the top list (1 for the first 39500, 2 for the second), and AGGREGATE returns the position of that occurrence. Now each tied rep appears once.
Making it look like a leaderboard
- Add data bars to the Sales column of the top-5 list: Home > Conditional Formatting > Data Bars.
- Put medals or ranks in front with a custom number format, or use
="#"&D2for labels. - Use SORTBY if you want to sort the names by a column that is not part of the result.
Pitfalls
- Text numbers. Sales stored as text are ignored by LARGE and sorted as text by SORT, so 9000 can appear above 45000. Convert them to numbers first.
- Spill space. TAKE/SORT needs five empty rows and two empty columns; otherwise you see
#SPILL!. - Fewer than 5 rows. LARGE returns
#NUM!when k is larger than the number of values; TAKE simply returns fewer rows. - Filtered data. These formulas include hidden rows. In Microsoft 365, filter inside the formula instead of with the AutoFilter.