Calculating Rank in Excel

Calculating Rank in Excel

To do some research on sorting, I hauled one of the big, dusty Excel books off my shelf, to see if there were any scintillating sorting secrets to uncover. Under Sorting, I saw “rank calculations” so I turned to that page, to see what it said about calculating rank in Excel.

The referenced page explained the RANK function, and included this warning, “Be sure the data set is sorted in either ascending or descending order.” Hmmm…I’d never heard that before, and a quick check in Excel’s Help proved that statement was wrong – the data set does NOT have to be sorted. Whew! I’ve been doing it right all along.

Do You Use the RANK Function?

Maybe you use the RANK function every day, but I rarely need it. If I want to see which products have the highest prices, or which students have the best scores, I’d probably just sort the list.

But now that I was in Excel Help anyway, I decided to learn a bit more about the RANK function. Maybe it has exciting features and hidden tricks to discover. (No, I hadn’t been drinking, I’m just optimistic.)

RANK Function Basics

If you give the RANK function a number, and a list of numbers, it will tell you the rank of that number in the list, either in ascending or descending order.

For example, here’s a list of 10 student test scores, in cells B2:B11. To find the rank of the score in cell B2, enter this formula in cell C2:

=RANK(B2,$B$2:$B$11)

Rank01

There are 3 arguments for the RANK function:

  • number: in this example, the number to rank is in cell B2
  • ref: We want to compare the number to the list of numbers in cells $B$2:$B$11. I used an absolute reference, so the referenced range will stay the same when we copy the formula down to the cells below
  • order: (optional) Use zero, or leave this argument empty, to find the rank in the list in descending order. For ascending order, type a 1, or any other number except zero. I left this blank, to find the rand in descending order. If you were comparing golf scores, you could type a 1, to rank in ascending order.

I copied the formula down to cell C11, and the scores were ranked in descending order, as promised.

Rank02

RANK Function With Ties

What happens to the ranking if some of the scores are tied? I was going to use the Olympics as an example, but it looks like every sport has different rules, so that won’t work!

In our example, if I change cell B7 to 43, it’s tied with cell B3. Both cells are now ranked as 2, and it doesn’t affect any of the other rankings. The score of 32 is still 4th, not 3rd, because there are 3 scores ahead of it.

So, if you were handing out awards to the top students,

  • the score of 45 would get the first place blue ribbon
  • the two students with 43 would each get a second place red ribbon
  • no one would get a third place ribbon (green? white?)
  • everyone else gets one of those orange “Participant” ribbons 😉

Rank03

Breaking Ties With the RANK Function

In some cases, ties aren’t allowed, so you have to find a way to break the tie. We could keep track of the number of minutes that each student worked on the test, and use that time to break any ties in the ranking.

I added the Test Times in column A, and a TieBreak formula in column D.

=IF(COUNTIF($B$2:$B$11,B2)>1,RANK(A2,$A$2:$A$11,1)/100,0)

Rank04

The TieBreak formula checks to see if there’s more than one instance of the number in the entire list ($B$2:$B$11).

  • If there is more than one instance, it ranks the Times in ascending order and divides that by 100, to get a decimal amount. Note: The divisor, 100, could be changed to another number, if you were working with a longer list.
  • If there is only one instance, the result is zero.

Finally, you can combine the RANK function results with the TieBreak results, to get the final ranking.

Rank05

Get the Excel File

For more details on breaking ties, and to get the sample file, go to the Excel Rank with Ties page on my Contextures site. The zipped Excel file is in xlsx format, and does not contain any macros.

And for more RANK formula examples, and to get the sample Excel file, go to the RANK formula in Excel, page on my Contextures site.
__________

26 thoughts on “Calculating Rank in Excel”

  1. To prevent ties, I include a column at left to number the rows 1,2,3,4,…., and I add this number to the scores (divided by a large number like 100,000). This guarantees each number is unique.

  2. A combination of RANK and lookup functions is very useful when you have a large list and the boss wants to see the current top ten headaches in the weekly report. Instead of sorting the list and copy-pasting the top ten out every week, you can use RANK to establish the top ten values, and lookup to pull out the other details of the cases.

    But tie-breaking is essential if you don’t want Joe Bloggs counted twice in the list, and Jane Smith missed out, because you looked up using a duplicate value.

  3. we must make small change in list
    list b2:b10
    the new list in a2 : a10 =

    =B2+ROW(A2)/10000000

    after that we use rank function on new list

    I’m waiting a better than this
    Thanks

  4. I use a variation of Dermot’s approach. This ensures that ties retain their relative order when ranked. In the approach you used, the lower tied value has a higher rank than the upper tied value, thus reversed in the ranked list.

  5. I experienced this problem with Rank last week, and I combined it with IF. My data range was F3:F22, and I used, i.e. on F3 ranking =IF(RANK(F3,$F$3:$F$22,1)-COUNTIF($F$3:$F$22,0)<0,1,RANK(F3,$F$3:$F$22,1)-COUNTIF($F$3:$F$22,0)+1)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.