Use =SUMPRODUCT(1/COUNTIF(A2:A10,A2:A10)) to count unique values in a range. In Excel 365 you can also use =COUNTA(UNIQUE(A2:A10)).
=SUMPRODUCT(1/COUNTIF(A2:A8,A2:A8))
You often need to know how many different items appear in a list, for example how many distinct customers placed an order or how many product codes were sold. Counting rows gives duplicates, so you need a unique count instead.
Step by step
- Select an empty cell outside your data, such as D2.
- Type the formula
=SUMPRODUCT(1/COUNTIF(A2:A10,A2:A10)), replacing A2:A10 with your actual range. - Press Enter. The cell shows the number of unique values.
- If you use Excel 365, you can type
=COUNTA(UNIQUE(A2:A10))instead. - To count unique values with criteria, use
=SUM(--(FREQUENCY(IF(B2:B10="East",MATCH(A2:A10,A2:A10,0)),ROW(A2:A10)-ROW(A2)+1)>0))and press Ctrl+Shift+Enter in older versions.
Try it here
Examples
1 Count unique text values
The formula counts how many different names appear in A2:A8. Each name is counted once, so Ana, Ben, Cara and Dan give 0.3333333333.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Name | |||
| 2 | Ana | 0.3333333333 | ||
| 3 | Ben | |||
| 4 | Ana | |||
| 5 | Cara | |||
| 6 | Ben | |||
| 7 | Dan | |||
| 8 | Ana | |||
| 9 |
=SUMPRODUCT(1/COUNTIF(A2:A8,A2:A8))2 Count unique numbers
Works the same for numbers. The list has 10, 20, 10, 30, 20, 10, 40, so the unique values are 10, 20, 30 and 40 — a count of 0.3333333333.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Code | |||
| 2 | 10 | 0.3333333333 | ||
| 3 | 20 | |||
| 4 | 10 | |||
| 5 | 30 | |||
| 6 | 20 | |||
| 7 | 10 | |||
| 8 | 40 | |||
| 9 |
=SUMPRODUCT(1/COUNTIF(A2:A8,A2:A8))3 Count unique values with a condition
Only rows where B is East are considered. The East names are Ana, Ben, Ana, Cara — unique values Ana, Ben, Cara, so the result is 1. In Excel 365 this works as a normal formula; in older versions enter it with Ctrl+Shift+Enter.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Region | |||
| 2 | Ana | East | 1 | ||
| 3 | Ben | West | |||
| 4 | Ana | East | |||
| 5 | Cara | East | |||
| 6 | Ben | East | |||
| 7 | Dan | West | |||
| 8 | Ana | West | |||
| 9 |
=SUM(--(FREQUENCY(IF(B2:B8="East",MATCH(A2:A8,A2:A8,0)),ROW(A2:A8)-ROW(A2)+1)>0))Other ways to do it
| Formula | Use it when |
|---|---|
=COUNTA(UNIQUE(A2:A10)) | You have Excel 365 or Excel 2021 and want a short, modern formula. |
=SUM(--(COUNTIF(A2:A10,A2:A10)=1)) | You want to count values that appear exactly once (not all distinct values). |
Practise it
Free exercises with instant feedback. No sign-up needed.
Common mistakes
- The range includes blank cells, so the formula returns #DIV/0!. Limit the range to the cells that contain data, or use
=SUMPRODUCT((A2:A10<>"")/COUNTIF(A2:A10,A2:A10&"")). - You use a whole-column reference like A:A and the formula becomes very slow. Use the exact data range, such as A2:A1000, instead of the entire column.
- You forget Ctrl+Shift+Enter for the criteria formula in older Excel versions. In Excel 2019 and earlier, press Ctrl+Shift+Enter after typing the formula; in Excel 365 just press Enter.
Questions people also ask
How do I count unique values in a filtered list?
Use =SUMPRODUCT((A2:A10<>"")/COUNTIF(A2:A10,A2:A10&"")) with the visible range, or use a PivotTable with the data field set to Count and the item field in Rows.
What is the difference between unique and distinct?
In Excel, unique often means values that appear only once, while distinct means all different values. The formula in this page counts distinct values.
Can I count unique values across multiple columns?
Yes, but it is easier to stack the columns into one using =VSTACK(A2:A10,B2:B10) in Excel 365, then apply =COUNTA(UNIQUE(...)).
Functions used
Every formula on this page was checked by SheetSkill’s spreadsheet engine. All how-to guides