How to mark the first occurrence of each value in Excel
Formula (Excel and Google Sheets)
=IF(COUNTIF($A$2:A2,A2)=1,"First","Repeat")Count from the top of the list down to the current row: =IF(COUNTIF($A$2:A2,A2)=1,"First","Repeat").
- Result on the example
- one result per row in
B2, filled down toB10 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in B2, filled down to B10. Change any input and the result updates, or edit the formula to experiment.
How it works
The range $A$2:A2 starts locked at the top and grows as you fill down, so each row counts only the rows above it plus itself. The first copy counts 1, later copies count 2 or more. Filter on "First" to keep one row per email.
=IF(COUNTIF($A$2:A2,A2)=1,"First","Repeat")Result"First"
$A$2:A2"ana@northwind.example"A range: one cell.
A2"ana@northwind.example"The value in A2.
COUNTIF($A$2:A2,A2)1COUNTIF: Counts cells that meet one condition.- range
$A$2:A2"ana@northwind.example" - criteria
A2"ana@northwind.example"
- range
COUNTIF($A$2:A2,A2)=1TRUEThe = operator tests whether the two sides are equal.
IF(COUNTIF($A$2:A2,A2)=1,"First","Repeat")"First"IF: Returns one value if a test is true, another if false.- logical_test
COUNTIF($A$2:A2,A2)=1TRUE - value_if_true
"First" - value_if_false
"Repeat"not used
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(COUNTIF($A$2:A2,A2)=1,"First","Repeat"). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =COUNTIF($A$2:A2,A2) | 1, 1, 1…Different result | The running count itself: 1 for the first copy, 2 for the second, and so on. Shows the occurrence number. |
Common mistakes
- Lock only the start of the range.
$A$2:$A$2wouldn't grow, andA2:A2would move entirely. - Sort first if "first" should mean the earliest date rather than the highest row.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Mark the first occurrence of each value
B2, show "First" for the first time each email appears and "Repeat" for later copies. Fill down to B10.Questions
How do I keep only the first occurrence?
Filter the column for "First", or use =UNIQUE(A2:A10) for a list of distinct values.
How do I number the occurrences?
Use the running count alone: =COUNTIF($A$2:A2,A2).
Checked by running on 2026-10-29: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.