How to find top or bottom N values in Excel

With this tutorial, you will learn how to find top 3, 5, 10 or n values in a dataset and retrieve matching data.

Want to identify the highest or lowest N values in a column or row? That sounds like a pretty easy thing to do. Need to return not only the values themselves but their names too? Oh, that could be a challenge. There are one or more criteria to be met. Hmm, is that even possible?! Yep, all this can be done with Excel formulas and this tutorial shows how.

Excel formula to find top 3, 5, 10, etc. values

To get the highest N values in a list, use the LARGE and ROWS functions together in this way:

LARGE(values, ROWS(A$2:A2))

For example, to find top N values in B2:B12, you enter the below formula in the topmost cell where you want the results to appear (D2), and then drag it through as many cells as needed.

=LARGE($B$2:$B$12, ROWS(A$2:A2))

To pull top 3 values, copy the formula to 3 cells.

To get top 5 values, copy the same formula to 5 cells.

To find top 10 values in a column, copy the formula to 10 cells.
Excel formula to find top values in a list

How this formula works:

The LARGE function compares all the numeric values in a range supplied for the 1st argument (array) and returns the largest value based on the position specified in the 2nd argument (k).

The ROWS function with an expanding range reference like ROWS(A$2:A2) generates the k values automatically. To create such a reference, we lock the row coordinate in the first cell with an absolute reference (A$2) and use a relative reference for the last cell (A2).

In the topmost cell where you enter the formula (D2 in this example), ROWS(A$2:A2) generates 1 for k, telling LARGE to return the max value. When copied to the below cells, the range reference expands by 1 row causing the k argument to increment by 1. For example, in D3, the reference changes to A$2:A3. The ROWS function counts the number of rows in A$2:A3 and returns 2 for k, so the LARGE function outputs the 2nd largest value.

Please note that we used A$2:A2 just for convenience because our data begins in row 2. You can use any column letter and any row number for the expanding range reference, say A$1:A1 or C$1:C1.

Excel formula to get bottom 3, 5, 10, etc. values in Excel

To find the lowest N values in a list, the generic formula is:

SMALL(values, ROWS(A$2:A2))

In this case, we use the SMALL function to extract the k-th smallest value and the ROWS function with an expanding range reference to generate the k number.

For example, to find bottom N values in the table below, use this formula:

=SMALL($B$2:$B$12, ROWS(A$2:A2))

Enter it in the topmost cell, and then drag down through as many cells as many values you want to get.
Excel formula to get bottom values in a column

Excel formula to find top N values in a row

If your data is organized horizontally in rows, then you can use the following generic formulas to find the highest or lowest values:

Get top values in a row:

LARGE(values, COLUMNS(A$2:A2))

Get bottom values in a row:

SMALL(values, COLUMNS(A$2:A2))

The formulas' logic is the same as in the previous example with the difference that you use the COLUMNS function rather than ROWS to "feed" the k value to LARGE and SMALL.

Let's say your table lists the results of 5 rounds for each participant like shown in the image below. You aim to find top 3 values in each row.

To have it done, enter the following formula in the upper-right cell (B10 in our case), and then drag it down and to the right:

=LARGE($B2:$F2, COLUMNS($A1:A1))

For the formula to copy correctly, we use a mixed reference for the array argument of LARGE that locks only the column coordinates ($B2:$F2).
Excel formula to find top 3 values in a row

To find bottom 3 values in each row, you can use an analogous SMALL formula:

=SMALL($B$2:$H$2, COLUMNS($A2:A2))

How to get matches of largest N values

In situation when you want to retrieve data relating to top values, use the classic INDEX MATCH formula together with LARGE as the lookup value:

INDEX(return_array, MATCH(LARGE(lookup_array, k), lookup_array, 0))

Where:

  • Return_array is a range from which to extract associated data (matches).
  • Lookup_array is a range where to search for the largest values.
  • K is position of the highest value to look for.

In the table below, you can find top 3 values by using the following approach.

To extract top 3 results, the formula in E3 is:

=LARGE($B$2:$B$12, D3)

Because the ranks are typed in separate cells, the ROWS function is not needed in this case - we simply reference the cell containing the k value (D3).

To retrieve the names, the formula in F3 is:

=INDEX($A$2:$A$12, MATCH(LARGE($B$2:$B$12, D3), $B$2:$B$12, 0))

Where A2:A12 are the names (return_array), B2:B12 are the results (lookup_array) and D3 is the position from largest (k).
Formula to get matches of largest 3 values

In a similar manner, you can get matches of bottom N values. For this, just use the SMALL function instead of LARGE.

To get bottom 3 results, the formula in E3 is:

=SMALL($B$2:$B$12, D3)

To pull the names, the formula in F3 is:

=INDEX($A$2:$A$12, MATCH(SMALL($B$2:$B$12, D3), $B$2:$B$12, 0))
Formula to get data associated with bottom 3 values

How this formula works:

The LARGE function gets the k-th largest value and passes it to the lookup_value argument of MATCH.

For instance, in F3, we are looking for the 1st largest value, which is 5.57. So, after replacing the LARGE function with its output, the formula reduces to:

=INDEX($A$2:$A$12, MATCH(5.57, $B$2:$B$12, 0))

The MATCH function determines the relative position of 5.57 in B2:B12, which is 9. This number goes to the row_num argument of INDEX, simplifying the formula further:

=INDEX($A$2:$A$10, 9)

Finally, the INDEX function returns the value from the 9th row in the range A2:A12, which is "Nick".

XLOOKUP formula

Microsoft 365 subscribers can achieve the same results by using the new XLOOKUP function:

=XLOOKUP(LARGE($B$2:$B$12, D3), $B$2:$B$12, $A$2:$A$12)

In this case, LARGE returns the k-th largest number directly to XLOOKUP as the lookup value.
XLOOKUP formula to get matches to top or bottom values

Compared to the INDEX MATCH formula, this syntax is much simpler. However, please keep in mind that XLOOKUP is only available in Excel 365. In Excel 2019, Excel 2016 and earlier versions, this formula won't work.

How to find top values with duplicates

The approach used in the previous example works fine for a dataset that has only unique numbers in the lookup column. Duplicates may lead to wrong results. For example, if the 1st and 2nd largest numbers happen to be the same, the LARGE function will return the same value for each, which is expected by design. But because MATCH returns the position of the first found match, the formula will output the first match twice like shown on the image below:
A problem with duplicates

To "break ties" and fix the problem, we need a more sophisticated MATCH function:

=INDEX($A$2:$A$12, MATCH(1, ($B$2:$B$12=LARGE($B$2:$B$12, D2)) * (COUNTIF(F$1:F1, $A$2:$A$12)=0), 0))

In all versions except Excel 365, it only works as an array formula. So, please remember to press Ctrl + Shift + Enter to complete the formula correctly.
Formula to find top values with duplicates

How this formula works:

Here, the MATCH function is configured to search for the number 1, which is the lookup value. The lookup array is constructed using the following logic:

Firstly, all the numbers are compared against the value returned by LARGE:

$B$2:$B$12=LARGE($B$2:$B$12, D2)

Secondly, the COUNTIF function with an expanding range reference checks if a given item is already in the top list. Please pay attention that the expanding range begins on the above row (F1) to avoid a circular reference.

COUNTIF(F$1:F1, $A$2:$A$12)=0

The result of the above operations are two arrays of TRUE and FALSE values, which are multiplied by each other. For example, in F3, we have the following arrays:

{FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE} * {TRUE;TRUE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE}

In the first array, there are two TRUE values that correspond to 5.57 (rank 1 and 2) - items 3 and 9. But in the second array, item 3 is FALSE because this name (Brian) is already in the list. The multiplication operation changes the logical values TRUE and FALSE into 1 and 0, respectively. And because multiplying by zero always gives zero, only item 9 "survives":

{0;0;0;0;0;0;0;0;1;0;0}

The MATCH function searches for "1" in this array, and returns its relative position (9), which is Nick.

Note. This solution implies that the return column (Name in our case) contains only unique values.

Tip. In Excel 365, you can use a lot simpler FILTER formula that handles ties automatically.

How to find top values in Excel with criteria

To get top values that match certain condition, express your criteria with the help of the IF function and nest them inside the formulas discussed in the previous sections.

As an example, let's find top 3 results in a given group. To have it done, we input the target group in F1 and type the ranks 1 to 3 in E5:E7 (please see the image below).

To extract top 3 results, enter the below formula in F5 and drag it though F7:

=LARGE(IF($B$2:$B$12=$F$1, $C$2:$C$12), E5)

To ensure that the LARGE function is only processing the results within the target group, we build an IF statement that compares a list of groups against F1.

To get the names, copy this formula in G5 through G7:

=INDEX($A$2:$A$12, MATCH(LARGE(IF($B$2:$B$12=$F$1, $C$2:$C$12), E5), IF($B$2:$B$12=$F$1, $C$2:$C$12), 0))

Here, we use the already familial INDEX MATCH LARGE combination but extend it with two logical tests:

LARGE(IF($B$2:$B$12=$F$1, $C$2:$C$12), E5) - IF checks if a group matches the target one in F1. The matches get into the array from which the LARGE function picks the highest value based on the rank in E5. The result becomes the lookup value for MATCH.

IF($B$2:$B$12=$F$1, $C$2:$C$12) - IF filters out irrelevant groups again, so only the results that belong to the target group make it into the lookup array, where MATCH searches for the lookup value.

These are array formulas that should be entered by pressing Ctrl + Shift + Enter simultaneously. Due to the ability of Excel 365 to handle arrays natively, it's sufficient to press the Enter key in this version.
Formula to find top values in Excel with criteria

In Excel 365, you can perform the same logical tests inside XLOOKUP and get the identical results:

=XLOOKUP(LARGE(IF($B$2:$B$12=$F$1, $C$2:$C$12), E5), IF($B$2:$B$12=$F$1, $C$2:$C$12), $A$2:$A$12)

Tips:

How to FILTER top or bottom values in Excel

In Excel 365, there is a simpler way to find largest N values by using new dynamic array functions such as SORT and FILTER.

SORT(FILTER(data, numbers>=LARGE(numbers, n)), sort_index, -1)

Where:

  • Data is the source table excluding column headers.
  • Numbers are the numeric values to rank.
  • N is the number of top entries to extract.
  • Sort_index the number of the column to sort by.

For example, to filter top 3 records in our set of data, the formula goes as follows:

=SORT(FILTER(A2:B12, B2:B12>=LARGE(B2:B12, 3)), 2, -1)

In this case, we set n to 3 because we're extracting top 3 results and sort_index to 2 since the numbers are in the second column.

The beauty of this formula is that you only need to enter it in one cell, and Excel automatically spills the results into as many cells as needed (this concept is called a spill range).
Filtering top values in Excel

To extract the lowest 3 results, the formula is:

=SORT(FILTER(A2:B12, B2:B12<=SMALL(B2:B12, 3)), 2, 1)
Filtering bottom values in Excel

How these formulas work:

Here, we use the FILTER function to filter the source data based on the criteria included in the 2nd argument.

To get top values, we construct the logical expression that checks if a given number is greater than or equal to the Nth highest number in the list (the 3rd largest number in our case): B2:B12>=LARGE(B2:B12, 3).

To get bottom values, we check if a number is less than or equal to the 3rd lowest number: B2:B12<=SMALL(B2:B12, 3).

The result of the logical test is an array of TRUE and FALSE values, which is used for filtering - only the entries corresponding to TRUE get into the final array:

=SORT({"Aiden",5.51;"Brian",5.57;"Nick",5.57}, 2, -1)

As you can see above, the FILTER function outputs the items in the same order they appear in the source range. To sort the results, we place the FILTER formula inside the SORT function and set the sort_order argument to either -1 (descending) or 1 (ascending).

That's how to find top values in Excel. I thank you for reading and look forward to seeing you on our blog next week!

Practice workbook for download

Excel formulas to find top or bottom values (.xlsx file)

165 comments

  1. Thanks very much for this tutorial. I am actually looking for help with an athletics query a bit like your first queries but i have these three reporting needs.

    My list is performances of all time. I have the following fields mark (time or length), athlete name, meeting, place, venue, date of event (dd/mm/yyyy), year of event.

    1) a list of ten best results by each athlete
    2) A list of best results for any given year (but only one per athlete)
    3) is there a way I can extract data by year into other sheets per year without copy and pasting - so initial sheet has data from 1920 to current data, could I have a sheet in this spreadsheet or another file that will automatically retrieve all data from say 1962?

    Any help would be appreciated

  2. I used the formula "=LARGE(IF($B$2:$B$12=$F$1, $C$2:$C$12), E5)" to get the largest value based on a criteria. Can I use AND so that the largest value is satisfying multiple criteria?

  3. I am trying to get the top n repeated values with criteria and wondering if it's possible with what you have done above. My data has two columns, one is Model Type and the other is Zone.
    I need to find the top 3 most repeated values in Zone by Model Type.

    Model Type Zone
    123 5
    123 5
    101 4
    101 3
    123 4

    I was able to get the following to work, when I just wanted the top 3 by zone, but now I need to differentiate by Model type as well. Can you help?

    = LET(
    distinct, UNIQUE(Zone),
    count, COUNTIFS(Zone, distinct),
    ordered, SORTBY(distinct, count,-1),
    INDEX(ordered, {1;2;3}))

    Zone =B2:B71
    ModelType = A2:A71

  4. Hi
    Is it possible to pick the top 10 absolute values from a list and then order them by real value so that the positive values are grouped at the top, largest to smallest, followed by the negative values, largest to smallest?

    For example:

    Currently my top 10 list looks like this:

    Entity Value
    B 66
    C -61
    A -53
    H -46
    F 38
    D 33
    G -31
    S -27
    O -23
    J 22

    I would like the data to look like this:
    Entity Value
    B 66
    F 38
    D 33
    J 22
    C -61
    A -53
    H -46
    G -31
    S -27
    O -23

    Thanks

    • Hi! There is an inaccuracy in your description. For negative numbers, you are using an ascending sort order. For positive numbers, you use a descending sort order. So you need to use two different sort orders on the data.
      By using the FILTER function, we can select the positive numbers and the negative numbers separately.
      Then, using the SORT function, we can sort them in the order we want.
      These two arrays of values can be combined in a vertical direction by using the VSTACK function.
      Based on this information, the formula could be as follows:

      =VSTACK(SORT(FILTER(A1:B10,B1:B10>0),2,-1), SORT(FILTER(A1:B10,B1:B10<0),2,1))

      • Hi I'm trying to find a formula to work out the name of largest value by row by the any individual date of a row I select any ideas?

        • Hi! If I understand your question correctly, to find the largest value in a row, you can use the examples from the article above. Change the range from column to row in the formulas. If necessary, replace the ROW function with the COLUMN function. If this is not what you wanted, please describe the problem in more detail.

  5. Hi,

    I'm trying the "How to find top values with duplicates" but when I enter it, all three of my array formulas are looking for the same Rank (E5 in your example) and returning the same Name. If I change E5 to E6, all the results change to second ranked Name.

    my formula is:
    =INDEX($A$67:$A$78, MATCH(1, ($B$67:$B$78=LARGE($B$67:$B$78,C80))*(COUNTIF(A$79:A79, $A$67:$A$78)=0), 0))

    Names are in A67-A78, Results are in B67-B78, Ranks are in C80-82. I'm looking to return the Top 3 Results in B80-82 & Top 3 Names in A80-82.

    • Hi! I can't check your formula as I don't have your data. However, note that this formula has no reference to E5. Perhaps you did not enter this formula as an array formula.

  6. Hi,

    This has been very helpful! Thank you!!!

    I do have a question though.

    I have Microsoft 365, so I am able to utilize the SORT FILTER option. I have done this successfully, and it pulls the top 3, and indexes the names associated, which is great. The only problem I am having is that sometimes, one of my top 3 is a zero value, and it pulls all the zero values.

    So this is the formula I am using:

    =SORT(FILTER(B4:D99,C4:C99>=LARGE(C4:C99,3)),2,-1)

    So for example, this would pull
    My Top 3 people, their score, frequency of score
    Tom, 24,2
    Julie, 12,1
    Molly, 0,0
    Jamie,0,0
    Kyle,0,0
    etc. until all my zero values have been accounted for.

    Is there a way I can modify this formula to exclude all zero values?

    Thank you for your time

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)