Running Count in Excel: Number Each Occurrence With COUNTIF
By ExcelReady TeamUpdated 6 min read
The short answer
A running count numbers each occurrence of a value as it appears down a list: the first Lena is 1, the second Lena is 2. In Excel, type =COUNTIF($B$2:B2,B2) in the first row and fill it down. The locked start ($B$2) and moving end (B2) make a range that grows by one row each time.
Key takeaways
- =COUNTIF($B$2:B2,B2) counts how many times the current value has appeared so far, including this row.
- Lock only the start of the range. $B$2:B2 grows as you fill down; $B$2:$B$8 would give the total count instead.
- A running count of 1 marks the first occurrence, and anything above 1 is a repeat.
- Join the value and its count, such as Lena-2, to make unique IDs for lookups.
- Use COUNTIFS with two expanding ranges for a running count with more than one condition.
On this page+
A running count in Excel numbers each occurrence of a value as you go down a list: the first time "Lena" appears she gets 1, the second time 2, the third time 3. One COUNTIF formula with a growing range does it, and it is the base for flagging duplicates, building unique IDs and finding the second or third match. This guide shows the formula, why the dollar signs matter, and the most useful ways to put a running count to work.
What is a running count?#
A running count is a count that updates row by row. Each row asks "how many times have I seen this value so far, including now?". The examples use this order list in A1:C8:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Customer | Status | Running count |
| 2 | 1001 | Lena | Paid | 1 |
| 3 | 1002 | Omar | Paid | 1 |
| 4 | 1003 | Lena | Open | 2 |
| 5 | 1004 | Ravi | Paid | 1 |
| 6 | 1005 | Omar | Paid | 2 |
| 7 | 1006 | Lena | Paid | 3 |
| 8 | 1007 | Ravi | Open | 2 |
Column D is the running count. Lena's third order, in row 7, shows 3. Don't confuse it with a running total, which adds up numbers row by row instead of counting values.
How to make a running count with COUNTIF#
Type this in D2 and fill it down to D8 (Windows: Ctrl+D; Mac: ⌘D):
=COUNTIF($B$2:B2,B2)COUNTIF counts the cells in a range that match a value. The trick is the range, $B$2:B2:
- $B$2 is locked with dollar signs, so the start always stays on row 2.
- B2 has no dollar signs, so the end moves down as you fill.
In D7 the formula has become =COUNTIF($B$2:B7,B7). It counts "Lena" in B2:B7 and finds her in rows 2, 4 and 7, so it returns 3. This kind of range is called an expanding range. The COUNTIF function guide covers the syntax, and the COUNTIF article shows other criteria.
Why the dollar signs matter#
The formula only works with the start locked and the end free. Compare what row 7 shows with each version:
| Formula in D2 | Becomes in D7 | Result in D7 | What it counts |
|---|---|---|---|
=COUNTIF($B$2:B2,B2) | =COUNTIF($B$2:B7,B7) | 3 | Lenas so far (correct) |
=COUNTIF(B2:B2,B2) | =COUNTIF(B7:B7,B7) | 1 | Only the current row |
=COUNTIF($B$2:$B$8,B2) | =COUNTIF($B$2:$B$8,B7) | 3 | All Lenas, on every Lena row |
The last version looks right in row 7 but shows 3 for every Lena row, including the first. That's a total count, not a running count. Press F4 on Windows or ⌘T on a Mac to cycle through the dollar sign options. The dollar sign guide to absolute references explains mixed references like this one in more detail.
Flag duplicates and first occurrences#
A running count of 1 means "first time seen", and anything higher is a repeat. Label the rows with IF:
=IF(COUNTIF($B$2:B2,B2)>1,"Repeat","First")Rows 4, 6, 7 and 8 show Repeat. To count how many different customers there are, count the 1s in the running count column:
=COUNTIF(D2:D8,1)The result is 3: Lena, Omar and Ravi. Filter column D to 1 to see a list of first orders only. To colour the repeats instead of labelling them, select B2:B8, choose Home > Conditional Formatting > New Rule > Use a formula, and enter =COUNTIF($B$2:B2,B2)>1. Every second and later occurrence is highlighted. For other ways to find and count repeated values, see how to count duplicates in Excel.
Build unique IDs and find the nth match#
Join the value and its running count to make a key that is unique on every row. In E2:
=B2&"-"&COUNTIF($B$2:B2,B2)Row 2 shows Lena-1, row 4 Lena-2 and row 7 Lena-3. Now a normal lookup can find any occurrence, not just the first. To get the order number of Lena's second order:
=XLOOKUP("Lena-2",E2:E8,A2:A8)The result is 1003. XLOOKUP needs Excel 2021 or Microsoft 365; in older versions use =INDEX(A2:A8,MATCH("Lena-2",E2:E8,0)), which returns the same order.
Running count with more than one condition#
COUNTIFS accepts several range and criteria pairs, and each range can expand. To number only each customer's paid orders:
=IF(C2="Paid",COUNTIFS($B$2:B2,B2,$C$2:C2,"Paid"),"")Lena's paid orders get 1 and 2 (rows 2 and 7), and her open order in row 4 stays blank. Both ranges must start on the same row and grow together, otherwise COUNTIFS returns #VALUE!.
For a plain row number that skips blank rows, use an expanding COUNTA: =IF(B2="","",COUNTA($B$2:B2)). The guide to auto-numbering rows covers that and other numbering methods.
Running counts in tables and long lists#
In an Excel table (Insert > Table), an expanding range such as $B$2:B2 can be adjusted inconsistently when new rows are added. This version always starts at the first row of the column:
=COUNTIF(INDEX([Customer],1):[@Customer],[@Customer])INDEX([Customer],1) is the first cell of the Customer column and [@Customer] is the current row, so the range still grows by one row each time.
A running count depends on row order. If you sort the list by date or by customer, the numbers recalculate for the new order, so Lena's "first" order may change. When you need numbers that stay fixed, such as IDs you have already sent to someone, copy the column and paste it back as values (Windows: Ctrl+Alt+V; Mac: ⌃⌘V, then choose Values).
Each row's COUNTIF checks every row above it, so the work grows quickly with the length of the list. A few thousand rows is fine; on hundreds of thousands, a pivot table or Power Query is faster.
Practise it#
Try the exercise on this page: one COUNTIF with a half-locked range numbers Lena's third order. Then practise COUNTIF in a live spreadsheet and practise relative and absolute references, where you'll fill formulas down and see exactly which parts move.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Number each customer's orders. Click D7 and count how many times the customer in B7 appears from B2 down to row 7, with the start of the range locked. Press Enter.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Running count | ||||
| 2 | Paid | ||||
| 3 | Paid | ||||
| 4 | Open | ||||
| 5 | Paid | ||||
| 6 | Paid | ||||
| 7 | Paid | ||||
| 8 | Open | ||||
| 9 | |||||
| 10 | |||||
| 11 |
Tip: The range starts at a locked $B$2 and ends at B7 on this row. The criteria is B7 itself.
Practise this in a lesson
Frequently asked questions
How do I number duplicates in Excel?
Use a running count: =COUNTIF($B$2:B2,B2) in the first row, filled down. The first time a value appears it shows 1, the second time 2, and so on.
Why does my running count show the same number on every row?
The range is fully locked, as in $B$2:$B$8, so every row counts the whole column. Lock only the start: $B$2:B2. If every row shows 1, the start isn't locked at all.
How do I find the first occurrence of each value?
Rows where the running count equals 1 are first occurrences. Use =IF(COUNTIF($B$2:B2,B2)=1,"First","Repeat") to label them, or filter the running count column to 1.
Does a running count work in an Excel table?
Yes, but a formula like $B$2:B2 can be adjusted oddly when the table grows. A safer version is =COUNTIF(INDEX([Customer],1):[@Customer],[@Customer]), which always starts from the first row of the column.