How to count unique values in Excel
Count unique values in Excel with a blank-safe formula, check the names behind your total, and test an empty range without counting a blank as a customer.

Practice what this post teaches
To count unique values in Excel, use FILTER to exclude blanks, UNIQUE to keep one copy of each value, and SUM to count the remaining nonblank entries. The worked formula below also returns zero when the source range is empty, and a separate visible list lets you check which names contribute to the total.
A distinct count without blanks
A distinct count counts each different value once, even when that value appears several times. In a customer export, repeated customer names therefore contribute one customer each, not one customer per row.
“Unique” can also mean values that appear exactly once. Those are different questions: a distinct customer count includes a returning customer, while an exactly-once count excludes that customer. Here, you'll calculate a distinct count.
The example uses Microsoft 365 Excel for Windows or Mac, with English function names and comma argument separators. You'll use dynamic arrays, which are formula results that can contain several values and automatically occupy neighboring cells.
A copyable customer count
Build the customer list in column A, calculate the distinct count in D2, and display the names behind the count starting in F2. Use an empty worksheet so existing content won't obstruct the visible list.
Enter the starting values exactly as specified below. “Leave empty” is an instruction, not text to type into a cell. Keep the empty-range test and restoration steps with the exercise so you can check both populated and empty source data.
Fictional exercise: distinct customers
Goal: Count each different nonblank customer once.
Empty-range rule: Return 0 when no customer names remain.
Starting worksheet cells:
A1: Customer
A2: Alder
A3: Birch
A4: Alder
A5: Leave empty
A6: Cedar
A7: Birch
A8: Leave empty
D1: Distinct customers
F1: Names counted
Keep F2:F8 empty before entering the formulas.
Enter in D2:
=SUM(--(UNIQUE(FILTER(A2:A8,A2:A8<>"",""))<>""))
Enter in F2:
=UNIQUE(FILTER(A2:A8,A2:A8<>"",""))
Expected starting results:
D2: 3
F2: Alder
F3: Birch
F4: Cedar
Manual check:
Alder counts as 1, Birch as 1, Cedar as 1.
1 + 1 + 1 = 3
Empty-range variation:
Clear the contents of A2:A8, not the formulas in D2 or F2.
Expected D2: 0
Expected F2: visually blank
Expected F3:F4: empty after the spill contracts
Restore the starting values:
Enter Alder in A2, Birch in A3, Alder in A4,
and Cedar in A6, then Birch in A7.
Leave A5 and A8 empty.
Expected D2: 3
Expected F2:F4: Alder, Birch, Cedar
Compare D2 with the names displayed in F2:F4 before continuing. Alder appears twice in the source but only once in the visible list. Birch behaves the same way, and Cedar contributes the remaining name. The count and the list should agree.
Don't type the results into F3 or F4 yourself. The formula in F2 fills those cells automatically. That behavior is called a spill, and the cells occupied by the result form its spill range.
The calculation inside the formula
The formula removes blank entries, reduces the remaining names to distinct values, and converts a nonblank check into numbers that SUM can add. Reading the calculation from the inside outward makes each part easier to check.
- FILTER examines A2:A8 and keeps entries that aren't empty. Its final argument supplies an empty string when no names qualify, preventing a no-results error.
- UNIQUE keeps one copy of each remaining value. By default, repeated names still appear once in the result.
- The final nonblank comparison checks each distinct value. A real name becomes TRUE; the empty-string fallback becomes FALSE.
- The double minus, called the double unary operator, converts TRUE to 1 and FALSE to 0.
- SUM adds those numbers and returns the customer count.
An array is simply a collection of values. F2 displays the array of distinct names, while D2 reduces its internal array to one number. Keeping both formulas is useful when you need to explain a count rather than merely report it.
UNIQUE also has an optional exactly_once argument. Turning that option on would answer a different question: which names occur only once in the source? In the fictional list, Cedar meets that rule; Alder and Birch don't.
If the difference between counting numbers, populated cells, and blanks is still unclear, try COUNT, COUNTA and COUNTBLANK before adapting the distinct-count formula.
An empty-range check
An empty-range check confirms that the formula counts customers rather than a blank placeholder. Clear the contents of A2:A8 now, leaving the formulas in D2 and F2 untouched, then check these results immediately.
Change:
Clear the contents of A2:A8 only.
Keep the formulas in D2 and F2.
Expected results:
D2: 0
F2: visually blank
F3:F4: empty after the spill contracts
FILTER's empty-string fallback prevents an error when no names remain. However, an empty string is still a result that occupies a position in an array. Using ROWS to count that fallback array would return one row, not zero customers.
Restore the starting data by entering Alder in A2, Birch in A3, Alder in A4, Cedar in A6, and Birch in A7. Leave A5 and A8 empty, then verify that both formulas return to their original results.
Restored source cells:
A2: Alder
A3: Birch
A4: Alder
A5: Leave empty
A6: Cedar
A7: Birch
A8: Leave empty
Expected results:
D2: 3
F2: Alder
F3: Birch
F4: Cedar
Counting mistakes and practical limits
The main mistakes are counting source rows instead of distinct values, blocking the visible list, and treating inconsistent names as clean data. Check those causes before changing a formula that otherwise works.
The wrong counting function
COUNT counts numeric values, so it isn't the right tool for counting customer names. COUNTA counts populated cells but doesn't remove repeated names. COUNTIFS counts rows meeting one or more conditions; by itself, it doesn't produce a distinct count.
A blocked spill range
If F2 shows a spill error, inspect F3:F8 for existing content before replacing the formula. Move or remove any content that shouldn't be there. The visible list needs free cells below F2; a blocked spill doesn't mean the customer-counting rule is wrong.
Inconsistent source values
Blank-safe isn't the same as clean-data-safe. A cell containing spaces isn't empty, and unintended spaces can make apparently identical names count separately. Ordinary UNIQUE comparisons aren't case-sensitive, so capitalization alone doesn't separate otherwise identical names.
The formula also counts names, not verified customer identities. Different people can share a name, and the same person can appear under different spellings. For a real customer report, a consistent customer identifier is usually a better counting field.
For a separate cleanup exercise, try Project: clean an HR export before applying a distinct count to another exported list.
Range and version limits
If your source grows, change A2:A8 to the same larger range in both formulas and in both places inside each FILTER call.
Source errors also need investigation; excluding blanks doesn't remove error values. Finally, older Excel versions without UNIQUE and FILTER need another method. Check function availability before troubleshooting the logic of a formula your version can't run.
Common questions
What's the difference between distinct values and values that appear exactly once? Distinct values include one copy of every different value, even when a value repeats. Values appearing exactly once exclude every value that has a duplicate.
How do I count unique values without counting blank cells? Use FILTER to exclude blanks, UNIQUE to remove duplicates, and SUM with a final nonblank check to count the results. The final check also prevents an empty-string fallback from being counted when the source is empty.
Why does my unique count show one when the source cells are empty? A formula that counts rows can count an empty-string fallback as one row. Check whether the returned value is nonblank before including that value in the total.
Can COUNTIFS count unique values? COUNTIFS counts rows that meet conditions, not distinct values directly. For the Microsoft 365 example in this article, FILTER and UNIQUE make the distinct names visible and easier to inspect.
Which Excel versions support UNIQUE and FILTER? Microsoft 365 Excel for Windows and Mac supports both functions, as do Excel 2021 and Excel 2024. This walkthrough uses Microsoft 365; older versions such as Excel 2019 don't support these functions.