Home › Excel basics › Count unique values

How to Count Unique Values in Excel

To count unique values in Excel 365, use =COUNTA(UNIQUE(A2:A8)). In older versions, =SUMPRODUCT(1/COUNTIF(A2:A8, A2:A8)) does the same job. Below you'll find both, plus how to count with a condition and the difference between "distinct" and "unique".

In this guide
  1. Distinct or unique?
  2. Excel 365: COUNTA + UNIQUE
  3. Older versions: SUMPRODUCT
  4. With a condition
  5. With a pivot table
  6. List them instead
  7. FAQ
AB
1CustomerRegion
2AnnaNorth
3BenSouth
4AnnaSouth
5ChrisNorth
6BenSouth
7AnnaNorth
8DanaEast

Seven orders, but how many different customers? Anna, Ben, Chris and Dana: 4.

Distinct or unique: which do you need?

QuestionAnswer hereCalled
How many different names are there?4 (Anna, Ben, Chris, Dana)Distinct values
How many names appear only once?2 (Chris, Dana)Unique values

Most people mean the first when they say "count unique values". Both are covered below.

Excel 365: COUNTA and UNIQUE

=COUNTA(UNIQUE(A2:A8))

UNIQUE returns the list of different names and COUNTA counts them: 4. For names that appear exactly once, set UNIQUE's third argument to TRUE:

=ROWS(UNIQUE(A2:A8, , TRUE))

Result: 2. If the range can contain empty cells, filter them out first, otherwise the blank counts as a value:

=COUNTA(UNIQUE(FILTER(A2:A100, A2:A100<>"")))

Older versions: SUMPRODUCT and COUNTIF

=SUMPRODUCT(1 / COUNTIF(A2:A8, A2:A8))

How it works: COUNTIF counts how often each name occurs. Anna gets 3 on each of her three rows, so each of those rows adds 1/3, together exactly 1. Every name adds up to 1, so the total is the number of different names: 4.

Empty cells cause #DIV/0!. This version skips them:

=SUMPRODUCT((A2:A100<>"") / COUNTIF(A2:A100, A2:A100 & ""))

To count names that appear only once:

=SUMPRODUCT(--(COUNTIF(A2:A8, A2:A8) = 1))

Large lists: the COUNTIF method compares every row with every other row. With tens of thousands of rows it gets slow; use UNIQUE or a pivot table instead.

Count unique values with a condition

How many different customers ordered in South? In Excel 365:

=COUNTA(UNIQUE(FILTER(A2:A8, B2:B8="South")))

South has Ben, Anna and Ben, so the answer is 2. If no row matches, FILTER returns #CALC!; wrap it as IFERROR(…, 0).

With a pivot table (no formula)

  1. Select the data and choose Insert › PivotTable.
  2. Tick Add this data to the Data Model and click OK.
  3. Drag Region to Rows and Customer to Values.
  4. Click the Customer field in Values, choose Value Field Settings and pick Distinct Count.

You now see the number of different customers per region. Without the Data Model tick, Distinct Count doesn't appear in the list. More in the pivot table guide.

List the unique values instead

Want the names, not the count? =UNIQUE(A2:A8) or =SORT(UNIQUE(A2:A8)) gives the list. In older versions, copy the column and use Remove Duplicates.

Frequently asked questions

Is counting unique values case-sensitive?

No. UNIQUE and COUNTIF treat "anna" and "Anna" as the same value.

Why does my unique count include an extra value?

Probably blanks or names with extra spaces ("Anna " and "Anna"). Filter out blanks and clean the list with TRIM first.

How do I count unique numbers only?

In Excel 365: =COUNT(UNIQUE(A2:A100)). COUNT ignores text, so only the different numbers are counted.

Can I count unique values across two columns?

Yes: =ROWS(UNIQUE(A2:B8)) counts the different combinations of both columns, such as Anna + North and Anna + South.