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
| A | B | |
|---|---|---|
| 1 | Customer | Region |
| 2 | Anna | North |
| 3 | Ben | South |
| 4 | Anna | South |
| 5 | Chris | North |
| 6 | Ben | South |
| 7 | Anna | North |
| 8 | Dana | East |
Seven orders, but how many different customers? Anna, Ben, Chris and Dana: 4.
Distinct or unique: which do you need?
| Question | Answer here | Called |
|---|---|---|
| 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)
- Select the data and choose Insert › PivotTable.
- Tick Add this data to the Data Model and click OK.
- Drag Region to Rows and Customer to Values.
- 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.