Quick answer
To count unique values in Excel for Microsoft 365, Excel 2021 or later, use =COUNTA(UNIQUE(B2:B9)): UNIQUE lists each value once and COUNTA counts the list. In older versions, =SUMPRODUCT(1/COUNTIF(B2:B9,B2:B9)) gives the same count, as long as the range has no empty cells. To count only the values that appear exactly once, use =COUNTA(UNIQUE(B2:B9,,TRUE)).
“How many customers ordered this month?” sounds like a count, but COUNTA counts orders, and a customer who ordered three times counts three times. Counting each customer once takes one more step, and Excel has a short formula for it in every version.
Distinct, unique, and the count you want
Two counts hide behind the word “unique”. The distinct values are every different value, counted once, so Ana, Ben, Ana and Cleo hold three. The values that appear only once are fewer: the same list has two, Ben and Cleo, because Ana appears twice. Most questions at work, such as how many customers, suppliers or products, want the distinct count, while the other answers questions such as which customers ordered only once.
Count distinct values with UNIQUE
In Microsoft 365, Excel 2021 and Excel 2024, UNIQUE returns each value in a range once, and COUNTA counts what it returns. Say an order log lists the customer on each order:
UNIQUE doesn’t care about capitals, so ANA and Ana count as one. If the column has empty cells, leave them out first, because UNIQUE returns an empty cell as one more value: =COUNTA(UNIQUE(FILTER(B2:B100,B2:B100<>""))).
To count values that appear exactly once, give UNIQUE its third argument: =COUNTA(UNIQUE(B2:B9,,TRUE)). In the order log above, every customer ordered more than once except Ridge Labs, so it returns 1.
Count distinct values in older versions
Excel 2019 and earlier have no UNIQUE, but COUNTIF can do the counting. Give each row a share of one: a customer who appears three times gets a third on each of their rows, and the shares add up to one per customer.
You don’t need the helper column. One formula does the same in a single cell:
An empty cell in the range makes that formula show #DIV/0!, because COUNTIF finds no matches for it and 1 divided by 0 fails. When the column can have gaps, use =SUMPRODUCT((B2:B100<>"")/COUNTIF(B2:B100,B2:B100&"")), which skips them.
Count distinct values with a pivot table
A pivot table can count distinct values too. On Windows, tick Add this data to the Data Model when you create it, put the column in Values, and choose Distinct Count in Value Field Settings. Without the Data Model, or on a Mac, put the column in Rows instead: the pivot table lists each value once, and the number of rows is your count. How to make a pivot table in Excel covers the steps.
Count distinct values that meet a condition
To count the customers in one region, filter the list before UNIQUE sees it: =COUNTA(UNIQUE(FILTER(B2:B9,A2:A9="North"))), with the regions in column A. In older versions, put the region in a pivot table’s Filters and count the rows as above.
Why the count is off
- A space at the end makes “Quill and Co ” a different customer from “Quill and Co”. Clean the column with TRIM first.
- An ID typed as a number and the same ID pasted as text are two values to UNIQUE.
- Spelling variants such as “Quill & Co” are different values. Make them the same before you count, with Find & Replace for instance.
To delete the repeats instead of counting them, see how to remove duplicates in Excel and the free lesson Remove duplicates and choose what counts as a copy. To check one list against another, see how to compare two columns.
Practice this in ProExcel
Count a list that a formula spills, so the count follows the list.
ProExcel checks your answer the moment you press Enter.
The free lessons Count what matches with COUNTIF and COUNTIFS and Fill a range with one formula, and fix #SPILL! practice the two halves of these formulas, and List each value once with UNIQUE goes further with UNIQUE.
Frequently asked questions
How do I count unique values in a column in Excel?
In Microsoft 365 and Excel 2021 or later, use =COUNTA(UNIQUE(B2:B100)). In older versions, use =SUMPRODUCT(1/COUNTIF(B2:B100,B2:B100)), which needs a range without empty cells.
How do I count distinct values in Excel 2016 or 2019?
Use =SUMPRODUCT(1/COUNTIF(B2:B100,B2:B100)), or =SUMPRODUCT((B2:B100<>"")/COUNTIF(B2:B100,B2:B100&"")) when the column has empty cells. Each value’s rows add up to one, so the total is the number of different values.
How do I count distinct values in a pivot table?
On Windows, tick Add this data to the Data Model when you create the pivot table, then choose Distinct Count in Value Field Settings. Otherwise, put the field in Rows and count the rows.
How do I count unique values with a condition?
Filter first, then count: =COUNTA(UNIQUE(FILTER(B2:B100,A2:A100="North"))) counts the different values in column B on the rows where column A says North.
What's the difference between unique and distinct values?
Distinct values are all the different values, each counted once. Unique, in the strict sense, means values that appear only once; UNIQUE’s third argument, TRUE, returns those.
Practice this with real formulas
ProExcel's free course turns each idea into a formula you type yourself, checked the moment you press Enter. Five minutes a lesson, on your phone or computer.