Flag or Keep the First Duplicate

Excel Formulas › Data Cleaning

All versionsCOUNTIF

To dedupe with a formula, mark each row as the first occurrence or a repeat. A running COUNTIF labels the first as unique and the rest as duplicates — then filter to keep only the firsts.


Quick formula: flag the first occurrence of each value:
=IF(COUNTIF($A$2:A2, A2) = 1, "First", "Duplicate")
A COUNTIF over the range from the top through the current row equals 1 only on the first appearance.

Functions used (tap for the full reference guide):

The example

First sees "First"; repeats see "Duplicate".

AB
1ValueFlag
2appleFirst
3appleDuplicate

The formula

The formula:

=IF(COUNTIF($A$2:A2, A2) = 1, "First", "Duplicate") // running count = 1 → first

How it works

How it works:

  1. COUNTIF($A$2:A2, A2) counts how many times the value has appeared up to this row — the absolute start with a relative end expands as you fill down.
  2. It equals 1 on the first occurrence, and more on repeats.
  3. Flag the firsts, then filter to "First" (or delete "Duplicate" rows) to dedupe.
  4. Combine columns for a multi-field duplicate check.

Lock the start, not the end. The magic is $A$2:A2 — an absolute top and a relative bottom. Filled down, the range grows row by row, so the count is “how many so far,” making the first hit unique. Use the whole-column COUNTIF($A:$A, A2) > 1 instead to flag every member of a duplicate set, firsts included.

Try it: interactive demo

Live demo

Values, one per line.

Variations

Any duplicate (all)

Mark every repeat:

=IF(COUNTIF($A:$A, A2) > 1, "Dup", "Unique")

Multi-column key

Two fields:

=COUNTIF($A$2:A2 & $B$2:B2, A2 & B2)

Count occurrences

How many total:

=COUNTIF($A:$A, A2)

Pitfalls & errors

$A$2:A2 is the trick. Absolute start, relative end — the count expands as you fill down.

First vs all. Use a whole-column COUNTIF to flag every duplicate, not just repeats.

Case-insensitive. COUNTIF ignores case; build a key first if case matters.

Practice workbook

📊
Download the free Flag or Keep the First Duplicate practice workbook
A duplicate-flag sheet with the all-duplicates, multi-column, and count variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I flag the first occurrence of a duplicate in Excel?
Use =IF(COUNTIF($A$2:A2, A2) = 1, "First", "Duplicate") — the running count is 1 only on the first appearance.
How do I mark every row in a duplicate set?
Use a whole-column count: =IF(COUNTIF($A:$A, A2) > 1, "Dup", "Unique").
How do I check duplicates across two columns?
Combine them: =COUNTIF($A$2:A2 & $B$2:B2, A2 & B2) (array-entered in older Excel).

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: Flag duplicates · Count unique values · Normalize match key

Function references: COUNTIF