ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Conditional math
  3. How to Rank by Group in Excel With COUNTIFS

How to Rank by Group in Excel With COUNTIFS

By ExcelReady Team·Updated November 3, 2026·6 min read

The short answer

RANK.EQ ranks against the whole list, so for a rank within each group use COUNTIFS. In D2, type =COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,">"&C2)+1 and fill down. It counts how many rows in the same group have a higher value and adds 1. Ties get the same rank, just like RANK.EQ.

Key takeaways

  • RANK.EQ can't rank within a group, but COUNTIFS can: count the bigger values in the same group, then add 1.
  • The formula is =COUNTIFS(group_range,this_group,value_range,">"&this_value)+1.
  • Lock both ranges with $ signs so they stay fixed as you fill down.
  • Swap ">" for "<" to rank the smallest value first, such as the fastest time.
  • Equal values in a group share a rank, and the next rank is skipped.
On this page+
  1. Why RANK.EQ can't rank by group
  2. How to rank by group with COUNTIFS
  3. The result: ranks within each region
  4. How to rank smallest first within a group
  5. How to break ties within a group
  6. How to find the top values in each group
  7. Common mistakes when ranking by group
  8. Practise it

To rank by group in Excel, use COUNTIFS instead of RANK.EQ: count how many rows in the same group have a higher value, then add 1. The formula =COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,">"&C2)+1 gives each rep a rank inside their own region, with ties sharing a rank. This guide is for anyone who needs "top seller per region" or "fastest per team" rankings, and it works in every version from Excel 2007 on.

Why RANK.EQ can't rank by group#

RANK.EQ compares a number against one whole range, and it has no argument for a condition. So =RANK.EQ(C2,$C$2:$C$9) ranks Kofi against every rep, not just the reps in his region.

All examples use this sales table in A1:C9:

ABC
1RegionRepSales
2NorthKofi5,200
3SouthMei6,100
4NorthRavi4,800
5SouthAna7,300
6NorthLena6,100
7SouthTom5,900
8NorthSam4,800
9SouthIvy6,400

Overall, Kofi ranks 6th: five reps sold more. Inside North, he ranks 2nd, behind only Lena. That second number is what most reports need. The guide to the RANK function in Excel covers the overall rank.

How to rank by group with COUNTIFS#

COUNTIFS counts rows that meet every condition you give it. To rank within a group, give it two conditions: the same group, and a higher value. In D2 type:

Excel formula
=COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,">"&C2)+1

Then fill down to D9 (Windows: Ctrl+D; Mac: ⌘D). Here is what each part does:

PartMeaning
$A$2:$A$9,A2Only count rows in the same region as this row
$C$2:$C$9,">"&C2Only count rows with higher sales than this row
+1Nobody higher means rank 1, one person higher means rank 2

The & joins the operator ">" to the value in C2, so for Kofi the condition becomes ">5200". Only Lena (6,100) is in North with more, so the count is 1 and the rank is 2. The COUNTIFS function guide explains the range and criteria pairs.

The $ signs lock both ranges, so they stay on rows 2 to 9 as you fill down. A2 and C2 have no $, so they move to A3 and C3 on the next row.

The result: ranks within each region#

After filling down, each region has its own 1, 2, 3:

RegionRepSalesRank in region
NorthKofi5,2002
SouthMei6,1003
NorthRavi4,8003
SouthAna7,3001
NorthLena6,1001
SouthTom5,9004
NorthSam4,8003
SouthIvy6,4002

The rows don't need to be sorted: COUNTIFS checks the whole range each time. Notice that Mei and Lena both sold 6,100 but are ranked separately, because they are in different regions.

Ravi and Sam tie on 4,800 in North, so both get rank 3. There is no rank 4 in North, which matches how RANK.EQ treats ties. The comparison of RANK.EQ and RANK.AVG explains the other way to handle ties.

How to rank smallest first within a group#

For times, costs or error counts, the smallest value should be rank 1. Change the operator from greater than to less than:

Excel formula
=COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,"<"&C2)+1

Now Ravi and Sam (4,800) share rank 1 in North, and Lena (6,100) becomes rank 4.

How to break ties within a group#

To give every row a different rank, add a second COUNTIFS that counts only the rows above the current one with the same group and value:

Excel formula
=COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,">"&C2)+COUNTIFS($A$2:A2,A2,$C$2:C2,C2)

The second part uses an expanding range: $A$2:A2 grows to $A$2:A3, $A$2:A4 and so on as you fill down. It always counts the current row, so it replaces the +1, and it adds one more for each earlier tie. Ravi keeps rank 3 and Sam, who comes later in the list, gets 4. Use this only when a unique rank is truly needed, such as picking one winner, and tell readers how ties were broken.

How to find the top values in each group#

Sometimes you need the value, not the rank: "what are the best and second-best sales in North?" MAXIFS gives the top one in Excel 2019 or later:

Excel formula
=MAXIFS(C2:C9,A2:A9,"North")

The result is 6,100. For the 2nd, 3rd or nth value, combine LARGE with FILTER in Excel 2021 or Microsoft 365:

Excel formula
=LARGE(FILTER(C2:C9,A2:A9="South"),2)

This returns 6,400, the second-highest South sale. In older versions, =LARGE(IF(A2:A9="South",C2:C9),2) does the same, but you must confirm it with Ctrl+Shift+Enter as an array formula. SMALL works the same way for the lowest values.

If you need group averages next to the ranks, the guide to averaging by group uses the same conditions with AVERAGEIFS, and COUNTIFS and SUMIFS with multiple conditions shows how to add a third condition, such as a month.

Common mistakes when ranking by group#

Check these when the ranks look wrong:

  • Missing $ signs. Without them, the ranges shift as you fill down and later rows skip part of the data.
  • The operator outside the quotes. Write ">"&C2, not >C2 or ">C2". Inside quotes, C2 is just text.
  • Forgetting the +1. Without it, the top rep in each group gets rank 0.
  • Extra spaces in group names. "North " with a trailing space is a different group from "North". Clean the column with TRIM.
  • Numbers stored as text. Text values are not counted as greater or smaller. Convert them with VALUE first.

Practise it#

Ranking by group is a classic job-test question because it combines COUNTIFS, locked ranges and a little logic. Practise COUNTIFS and SUMIFS in a live spreadsheet, then practise LARGE and SMALL for top and bottom values: you type the formula and it checks it instantly. Or try the exercise on this page and rank Kofi within his region.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Rank each rep's sales within their region. In D2, write a COUNTIFS formula that counts rows in the same region (A2:A9) with higher sales (C2:C9) than C2, then add 1. Lock the ranges with $ signs and press Enter.

fx
ABCDE
1
Region
Rep
Sales
Rank in region
2
North
Kofi
5200
3
South
Mei
6100
4
North
Ravi
4800
5
South
Ana
7300
6
North
Lena
6100
7
South
Tom
5900
8
North
Sam
4800
9
South
Ivy
6400
10
11
12

Tip: Two pairs: the region range with A2, and the sales range with ">"&C2. Then add 1 after the closing bracket.

Practise this in a lesson

LessonCOUNTIFS and SUMIFSCount and sum with several conditions at once, and learn why SUMIFS puts the sum range first.LessonLARGE and SMALLFind the second-highest, top 3 or second-lowest value, a favorite interview question.Function guideCOUNTIFSCount rows that meet several conditions with COUNTIFS. Examples for text, number ranges and between-values, plus a live exercise.

Frequently asked questions

How do I rank within a group in Excel?

+

Use COUNTIFS: =COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,">"&C2)+1. It counts the rows in the same group with a higher value and adds 1, giving the rank inside that group.

Can RANK.EQ rank by group?

+

No. RANK.EQ ranks a number against one whole range and has no condition argument. Use COUNTIFS for a rank within each group, or sort the data by group and rank each block separately.

How do I rank by group from smallest to largest?

+

Change the operator to less than: =COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,"<"&C2)+1. The smallest value in each group then gets rank 1.

How do I rank by group without ties?

+

Add a second COUNTIFS that counts earlier rows with the same group and value: =COUNTIFS($A$2:$A$9,A2,$C$2:$C$9,">"&C2)+COUNTIFS($A$2:A2,A2,$C$2:C2,C2). The first of two equal values gets the higher rank.

Does the data need to be sorted to rank by group?

+

No. The COUNTIFS formula looks at every row in the range, so groups can be mixed in any order.

Sources

  • COUNTIFS function - Microsoft Support
  • RANK.EQ function - Microsoft Support
  • LARGE function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. Why RANK.EQ can't rank by group
  2. How to rank by group with COUNTIFS
  3. The result: ranks within each region
  4. How to rank smallest first within a group
  5. How to break ties within a group
  6. How to find the top values in each group
  7. Common mistakes when ranking by group
  8. Practise it

Keep reading

Math· 6 min read

RANK Function in Excel: Rank Scores and Sales

RANK.EQ returns a number's position in a list. Write =RANK.EQ(B2,$B$2:$B$8) to rank the value in B2 against the whole column, with the largest value ranked 1. Add a third argument of 1 to rank smallest first. Tied values share a rank and the next rank is skipped. RANK does the same job and still works in every version of Excel.

Conditional math· 7 min read

COUNTIFS and SUMIFS: Multiple Conditions in Excel

COUNTIFS counts rows that meet several conditions, and SUMIFS adds numbers from those rows. Each condition is a pair: a range, then its criteria. A row counts only if it matches every pair. SUMIFS puts the sum range first: =SUMIFS(E2:E9,A2:A9,"North",C2:C9,"Laptop") totals North laptop revenue.

Comparisons· 6 min read

RANK.EQ vs RANK.AVG: How Excel Handles Ties

RANK.EQ and RANK.AVG both return a number's position in a list. They differ only when values tie. RANK.EQ gives every tied value the best rank they share, so two values tied for 2nd both get 2. RANK.AVG gives them the average of the ranks they cover, so both get 2.5. Use RANK.EQ for leaderboards and RANK.AVG for statistics.

More on conditional math

  • Running Count in Excel: Number Each Occurrence With COUNTIF
  • How to Sum by Category in Excel
  • Sum by Date Range or Month in Excel With SUMIFS
  • How to Sum by Month in Excel With SUMIFS
  • How to Sum by Quarter in Excel
  • How to Sum by Week in Excel
All conditional math articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free