Rank Values Within Each Group

Excel Formulas › Statistics

All versionsCOUNTIFS

Rank salespeople within each region, or students within each class — a separate leaderboard per group. COUNTIFS counts how many in the same group score higher, giving a per-group rank.


Quick formula: rank value B2 within its group A2:
=COUNTIFS(group, A2, value, ">"&B2) + 1
Count the higher scorers in the same group, plus one — that’s the rank within the group.

Functions used (tap for the full reference guide):

The example

Ranked inside each region.

ABC
1RegionSalesRank
2East951
3East802
4West901

The formula

The formula:

=COUNTIFS(groups, A2, values, ">"&B2) + 1 // rank within the group

How it works

How it works:

  1. COUNTIFS(groups, A2, values, ">"&B2) counts how many rows in the same group have a higher value.
  2. Add 1 so the top value is rank 1.
  3. This gives an independent ranking within each group, unlike RANK which ranks across everything.
  4. Use < instead of > to rank ascending (smallest = rank 1).

Ties share a rank. Two equal values both get the same rank, and the next value skips one (1, 1, 3). To break ties, add a tiebreaker COUNTIFS on a second column, or use the row order.

Try it: interactive demo

Live demo

Lines “group,value”; rank within group.

Variations

Ascending rank

Smallest first:

=COUNTIFS(grp, A2, val, "<"&B2) + 1

Break ties

Add a second key:

=... + COUNTIFS(grp,A2,val,B2,id,"<"&id2)

Top-N flag per group

Mark the top 3:

=IF(rank<=3, "Top 3", "")

Pitfalls & errors

Ties share ranks. Equal values get the same rank; add a tiebreaker if you need unique ranks.

Concatenate the criteria. Use ">"&B2, not ">B2".

Aligned ranges. The group and value ranges must cover the same rows.

Practice workbook

📊
Download the free Rank Values Within Each Group practice workbook
A within-group rank sheet with ascending, tiebreak, and top-N variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I rank values within each group in Excel?
Use =COUNTIFS(groups, A2, values, ">"&B2) + 1. It counts higher values in the same group and adds one, giving a per-group rank.
How do I rank ascending within a group?
Use < instead of >: =COUNTIFS(groups, A2, values, "<"&B2) + 1.
How do I break ties?
Add a tiebreaker COUNTIFS on a second column (like an ID or timestamp) so equal values get distinct ranks.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Rank values · Percentile rank · Distinct count by group

Function references: COUNTIFS · RANK