Confident CellsExcel practice Start free

Count unique values in Excel

Updated 26 November 2026 · 4 min read

In Excel 365, =COUNTA(UNIQUE(A2:A21)) counts how many different values are in A2:A21. UNIQUE makes a list with each value once, and COUNTA counts that list. In Excel 2019 and older, use =SUMPRODUCT(1/COUNTIF(A2:A21,A2:A21)). UNIQUE works in Excel 365, Excel 2021 and later and Excel for the web, on Windows and Mac; the SUMPRODUCT formula works in every version.

Counting unique values at a glance

You want to countExcel 365 and 2021Excel 2019 and older
Different values=COUNTA(UNIQUE(A2:A9))=SUMPRODUCT(1/COUNTIF(A2:A9,A2:A9))
Different values, with blanks in the list=COUNTA(UNIQUE(FILTER(A2:A9,A2:A9<>"")))=SUMPRODUCT((A2:A9<>"")/COUNTIF(A2:A9,A2:A9&""))
Values that appear only once=COUNTA(UNIQUE(A2:A9,,TRUE))=SUMPRODUCT(--(COUNTIF(A2:A9,A2:A9)=1))
Different values in one group=COUNTA(UNIQUE(FILTER(A2:A9,B2:B9="North")))=SUMPRODUCT((B2:B9="North")/COUNTIFS(A2:A9,A2:A9,B2:B9,B2:B9))
Different pairs across two columns=ROWS(UNIQUE(A2:B9))Join the columns in a helper column first

Each one is worked through below.

A worked example

A list of 8 orders has some customers more than once. How many different customers are there?

By hand, you'd write each customer down the first time you see them: Harbour, Ashby, Kestrel, Northgate. Ashby, Harbour and Kestrel come up again, but they're already on your list. That's 4 different customers.

ABCD
1CustomerEach one onceHow many
2HarbourHarbour4
3AshbyAshby
4KestrelKestrel
5AshbyNorthgate
6Northgate
7Harbour
8Kestrel
9Harbour
C2 holds =UNIQUE(A2:A9), which spills a list with each customer once. D2 holds =COUNTA(UNIQUE(A2:A9)).
=COUNTA(UNIQUE(A2:A9))

You don't need the list in column C to get the count: the formula in D2 does both steps at once. There's more on UNIQUE in UNIQUE and FILTER.

In older Excel: SUMPRODUCT and COUNTIF

Excel 2019 and older don't have UNIQUE. This formula gives the same 4:

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

Here's how it works. COUNTIF counts how many times each row's customer appears: Harbour 3 times, so each Harbour row gets 1/3. Three thirds add up to 1. Ashby appears twice, so each Ashby row gets 1/2, and two halves make 1. Every customer adds up to exactly 1, however many times they appear, so the total is the number of different customers. Here are the steps laid out in columns:

ABCDE
1CustomerTimes listedShare
2Harbour30.333Total4
3Ashby20.5One formula4
4Kestrel20.5
5Ashby20.5
6Northgate11
7Harbour30.333
8Kestrel20.5
9Harbour30.333
B2 holds =COUNTIF($A$2:$A$9,A2) and C2 holds =1/B2, both copied down. E2 adds the shares, and E3 holds =SUMPRODUCT(1/COUNTIF(A2:A9,A2:A9)), which does it all in one cell.

SUMPRODUCT is there so that older Excel works out COUNTIF for every row at once. It works without pressing any special keys. On long lists of thousands of rows it can be slow, because COUNTIF runs once for every row.

Leaving out the blanks

If the list has empty cells, UNIQUE counts "empty" as one more value, so the answer is 1 too high. Here the list has 4 different customers and 2 gaps, so =COUNTA(UNIQUE(A2:A9)) gives 5 (D2 on the sheet below). Filter the blanks out first:

=COUNTA(UNIQUE(FILTER(A2:A9,A2:A9<>"")))
ABCD
1CustomerCountingAnswer
2HarbourBlanks left in5
3AshbyBlanks filtered out4
4Older Excel4
5Kestrel
6Northgate
7Harbour
8
9Ashby
D2 holds =COUNTA(UNIQUE(A2:A9)), which counts the gaps as one more value. D3 holds =COUNTA(UNIQUE(FILTER(A2:A9,A2:A9<>""))) and D4 holds =SUMPRODUCT((A2:A9<>"")/COUNTIF(A2:A9,A2:A9&"")). Both give 4.

The plain SUMPRODUCT formula gives #DIV/0! when there's a blank, because COUNTIF finds no empty cells to match. In the older Excel version, &"" fixes that, and (A2:A9<>"") gives each blank row a share of 0.

Different values, or values that appear once?

"Unique" can mean two things. "How many different customers?" is 4 in the worked example. "How many customers ordered only once?" is 1, because only Northgate appears once. Some people call the first one "distinct". For the second, add TRUE as UNIQUE's third part:

=COUNTA(UNIQUE(A2:A9,,TRUE))
ABCD
1CustomerCountingAnswer
2HarbourDifferent customers4
3AshbyOrdered only once1
4KestrelOrdered more than once3
5Ashby
6Northgate
7Harbour
8Kestrel
9Harbour
Column D holds, from the top: =COUNTA(UNIQUE(A2:A9)), =COUNTA(UNIQUE(A2:A9,,TRUE)) and the first take away the second.

The two commas leave UNIQUE's middle part empty: that part is for going across columns, which you don't need here. Taking one count from the other gives the customers who came back, 3. To see which ones are repeated, see finding duplicates.

Different values in one group

To count different values that match a condition, such as different customers in the North, filter first. The North orders are from Harbour (three times), Kestrel and Northgate, so 3 different customers.

ABCDE
1CustomerRegionRegionCustomers
2HarbourNorthNorth3
3AshbySouthSouth2
4KestrelNorth
5AshbySouth
6NorthgateNorth
7HarbourNorth
8KestrelSouth
9HarbourNorth
E2 holds =COUNTA(UNIQUE(FILTER($A$2:$A$9,$B$2:$B$9=D2))), copied down. The South has Ashby twice and Kestrel, so 2.

Kestrel ordered in both regions, so it counts once in each. In older Excel, =SUMPRODUCT((B2:B9="North")/COUNTIFS(A2:A9,A2:A9,B2:B9,B2:B9)) gives the same 3. If no row matches, FILTER gives #CALC!. Wrapping the count as =IFERROR(ROWS(UNIQUE(FILTER(A2:A9,B2:B9="West"))),0) shows 0 instead. Giving FILTER a third part, "", doesn't help here, because COUNTA counts that empty text as 1.

Common mistakes

The count is one too high

There's a blank in the range, or the heading is included. Start at row 2 and filter out the blanks, as above.

The same name counted twice

"Ashby" and "Ashby " (with a space on the end) are different to Excel. Tidy the list with TRIM first. Capitals don't matter: UNIQUE treats ASHBY and Ashby as the same.

#NAME? in older Excel

UNIQUE isn't in Excel 2019 or older, so the formula shows #NAME?. Use the SUMPRODUCT formula.

COUNTA on its own

=COUNTA(A2:A9) counts every order, 8, so a customer who ordered three times counts 3 times. Wrap the range in UNIQUE first. For more on COUNTA and the other counting functions, see counting cells with text.

Try it now

Your turn

Some customers have ordered more than once. In H1, work out how many different customer IDs there are in A2:A21.

ABCDEFGH
1Customer IDAmount (£)Different customers
21038160
3103733
41042118
51047144
61039148
7103253
8103260
91043151
101031259
111037126
12103786
131046172
14104495
151042210
16103847
171031118
18104766
191050240
20103981
211032129

Open this in Try a formula: the same sheet with the answer filled in, to change or share by link.

Part of Excel data cleaning practice: every lesson on the topic, with a project in Excel.

Where it works

UNIQUE and FILTER work in Excel 365, Excel 2021 and later, and Excel for the web, on Windows and Mac. SUMPRODUCT and COUNTIF work in every version of Excel, and COUNTIFS in Excel 2007 and later.

Questions

How do I count unique values with a condition?

Filter the list first, then count the different values in what is left: =COUNTA(UNIQUE(FILTER(A2:A50,B2:B50="North"))) counts the different customers in the North. If nothing might match, use =IFERROR(ROWS(UNIQUE(FILTER(A2:A50,B2:B50="North"))),0), which shows 0 in place of the #CALC! error. In Excel 2019 and older, use =SUMPRODUCT((B2:B50="North")/COUNTIFS(A2:A50,A2:A50,B2:B50,B2:B50)), which gives the same count without UNIQUE or FILTER.

How do I count unique values in Excel without the UNIQUE function?

Use =SUMPRODUCT(1/COUNTIF(A2:A50,A2:A50)). COUNTIF counts how many times each row's value appears, so a value listed three times gives each of its rows a third. The thirds add up to 1, so every different value adds exactly 1 to the total. It works in every version of Excel. If the list has blanks, use the version with &"" shown above.

What's the difference between distinct and unique values?

Distinct values are every different value, each counted once: in Harbour, Ashby, Harbour there are 2. Unique values sometimes means the ones that appear exactly once: there, only Ashby, so 1. Excel's UNIQUE gives the distinct values unless you add TRUE as its third part. =COUNTA(UNIQUE(A2:A50)) counts distinct values and =COUNTA(UNIQUE(A2:A50,,TRUE)) counts the ones that appear once.

How do I count unique values and ignore blanks?

Filter out the empty cells before UNIQUE: =COUNTA(UNIQUE(FILTER(A2:A50,A2:A50<>""))). Without the filter, UNIQUE keeps one empty value, so the count is 1 too high. In older Excel, use =SUMPRODUCT((A2:A50<>"")/COUNTIF(A2:A50,A2:A50&"")). A cell holding only a space isn't blank to Excel, so tidy the list with TRIM first if there may be stray spaces.