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.

Intermediate TAKE SORT SORTBY FILTER LARGE INDEX MATCH AGGREGATE ROWS

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:

D2fx=TAKE(SORT(A2:B9,2,-1),5)
ABCDE
1RepSales
2Ana48200Chloe52700
3Ben39500Ana48200
4Chloe52700Hana46900
5Dev31800Eva44100
6Eva44100Ben39500
7Femi36500
8Gus27600
9Hana46900

Names and values spill together into D2:E6.

  • SORT(A2:B9,2,-1): sort by column 2 (Sales), -1 for largest first.
  • TAKE(...,5): keep the first 5 rows. Change it to -5 on 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:

E2fx=INDEX($A$2:$A$9,MATCH(LARGE($B$2:$B$9,D2),$B$2:$B$9,0))
ABCDEF
1RepSalesTopNameSales
2Ana482001Chloe
3Ben395002
4Chloe527003
5Dev318004
6Eva441005
7Femi36500
8Gus27600
9Hana46900

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:

Formula
=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 ="#"&D2 for 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.
Tip. For ranks rather than a list, see How to rank numbers with ties in Excel. For a dynamic chart of the top five, point the chart at the spilled range; charts are introduced in Charts: choosing the right chart, combo charts and sparklines, and spilling formulas in Dynamic arrays: spill, FILTER, SORT, UNIQUE, SEQUENCE and #.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 15 KB

More how-to recipes