Excel How to Count Unique Values: 4 Easy Ways

Formulas & functions · Updated November 23, 2026

To count unique values in Excel, use =SUMPRODUCT(1/COUNTIF(range, range)) for a quick total, or =COUNTA(UNIQUE(range)) if you have Excel 365 or 2021. Both return the number of distinct entries, ignoring blanks and duplicates. Below we break down each method, when to use it, and how to handle common pitfalls like blanks, errors, and case sensitivity.

Why Counting Unique Values Is Tricky in Excel

Excel has built-in functions for counting numbers (COUNT), non-empty cells (COUNTA), and cells meeting a condition (COUNTIF), but none of them directly count unique entries. The challenge is that a “unique count” requires Excel to look at the entire range, identify each distinct value, and then count them—something that wasn’t possible with a single function before the UNIQUE function arrived in Excel 365. Older workarounds use array formulas that can be slow on large datasets, and many users accidentally count blanks or #DIV/0! errors when they try to adapt a formula they found online.

The UNIQUE Function: The Modern Solution (Excel 365 / 2021)

If you have Microsoft 365, Excel 2021, or Excel for the web, the simplest way is to combine UNIQUE with COUNTA or ROWS.

  • Count unique values in a single column (e.g., names in A2:A20):
    =COUNTA(UNIQUE(A2:A20)) – returns the number of distinct text/numbers, ignoring blanks.
  • Count unique numeric values only:
    =SUM(--(UNIQUE(A2:A20)<>&"")) – but COUNTA already ignores blanks, so this is rarely needed.
  • Count unique values across multiple columns (e.g., first names in A2:A20 and last names in B2:B20):
    =COUNTA(UNIQUE(A2:B20)) – but note that UNIQUE returns unique rows, so you might get more than the number of unique individual names. To count unique pairs, use =ROWS(UNIQUE(A2:B20)).

How it works: UNIQUE returns an array of distinct values from the range. COUNTA counts non-empty cells in that array. Because UNIQUE ignores blanks by default, you don’t need extra filtering. This formula is dynamic—if you add or remove entries, the count updates automatically.

Mac and web: The same formulas work in Excel for Microsoft 365 on Mac and in Excel for the web. No special steps.

The Classic SUMPRODUCT/COUNTIF Formula (All Excel Versions)

For older Excel versions (2019 and earlier), the standard formula is:

=SUMPRODUCT(1/COUNTIF(range, range))

Example: with items in A2:A10, enter =SUMPRODUCT(1/COUNTIF(A2:A10, A2:A10)). If A2:A10 contains {Apple, Banana, Apple, Cherry, Banana, Apple, Date, Cherry, Apple}, the formula returns 4 (Apple, Banana, Cherry, Date).

How it works: COUNTIF(range, range) returns an array of counts—for each cell, how many times that value appears. For example, if “Apple” appears 4 times, the array has 4 fours. Dividing 1 by each count gives fractions: 1/4 for each Apple, 1/2 for each Banana, etc. Summing those fractions yields the number of distinct values. This is a classic array formula, but SUMPRODUCT handles the array without needing Ctrl+Shift+Enter.

Important caveats:

  • If the range contains any blank cells, COUNTIF counts them as a value, and 1/COUNTIF becomes 1/0, causing a #DIV/0! error. To ignore blanks, use =SUMPRODUCT((A2:A20<>"")/COUNTIF(A2:A20, A2:A20&"")).
  • If the range contains any error values (like #N/A), the formula will return an error. You would need to remove or handle errors first.
  • This formula is case-insensitive: it treats “Apple” and “apple” as the same. To make it case-sensitive, you need a more complex array formula with FREQUENCY and MATCH—see the next section.

Counting Unique Values with Criteria (Filtered Count)

Often you need to count unique values that meet a condition, like unique products sold in a specific region. For Excel 365, combine UNIQUE with FILTER:

Example: products in A2:A20, regions in B2:B20. To count unique products in “East” region:
=COUNTA(UNIQUE(FILTER(A2:A20, B2:B20="East")))

For older Excel, use a SUMPRODUCT array formula with a condition:
=SUMPRODUCT((B2:B20="East")*(A2:A20<>"")/COUNTIFS(A2:A20, A2:A20, B2:B20, B2:B20))
This counts unique combinations of product and region, but if you want unique products only (ignoring region in the unique check), you need a more advanced formula with FREQUENCY.

Note: The COUNTIFS version counts unique pairs (product+region). To count unique products regardless of region, use a helper column or a dynamic array formula.

Case-Sensitive Unique Count (Advanced)

If you need “Apple” and “apple” to count as two different values, the standard formulas won’t work because they are case-insensitive. One workaround uses SUMPRODUCT with FREQUENCY and MATCH:

For a range A2:A10, enter this array formula (confirm with Ctrl+Shift+Enter in older Excel, or just Enter in Excel 365):
=SUMPRODUCT(--(FREQUENCY(MATCH(A2:A10, A2:A10, 0), ROW(A2:A10)-ROW(A2)+1)>0))

This works by using MATCH to find the first occurrence of each value, then FREQUENCY to count how many first occurrences fall into each bin. It is case-sensitive because MATCH is case-sensitive by default. However, it does not ignore blanks—blanks will be counted as a unique value. To ignore blanks, add a condition: =SUMPRODUCT((A2:A10<>"")*(FREQUENCY(IF(A2:A10<>"", MATCH(A2:A10, A2:A10, 0)), ROW(A2:A10)-ROW(A2)+1)>0)) and confirm as an array formula.

How to Choose the Right Method

Your choice depends on your Excel version and your data:

  • If you have Excel 365 or 2021: Use UNIQUE—it’s simpler, faster, and more flexible. For a simple count, =COUNTA(UNIQUE(range)) is all you need.
  • If you have Excel 2019 or earlier: Use the SUMPRODUCT(1/COUNTIF(...)) formula, but be prepared to handle blanks and errors.
  • If you need case-sensitive counting: Use the FREQUENCY/MATCH array formula, regardless of version (but it’s easier to use UNIQUE with a helper column that uses EXACT).
  • If you need to count unique values with criteria: Use UNIQUE + FILTER in Excel 365; otherwise, use a PivotTable or a helper column.

Common Problems and Pitfalls

  • #DIV/0! error: Caused by blank cells in the range when using SUMPRODUCT(1/COUNTIF(...)). Fix by adding (range<>"") as shown above.
  • Counting blanks as a unique value: The UNIQUE function ignores blanks, but SUMPRODUCT(1/COUNTIF) does not. Always filter blanks if using the classic formula.
  • Case sensitivity: Most users expect “Apple” and “apple” to be the same, but if you need them distinct, use the case-sensitive method.
  • Performance on large data: SUMPRODUCT(1/COUNTIF) can be slow on tens of thousands of rows because it calculates a count for each cell. UNIQUE is faster and more memory-efficient.
  • Using full column references (e.g., A:A): This can cause errors or slow calculations because it includes 1,048,576 cells. Limit the range to your actual data.

Alternatives: PivotTables and Power Query

If you prefer a visual approach or need to refresh counts frequently, a PivotTable is a great alternative. Drag the field you want to count into the Rows area, then right-click and choose “Value Field Settings” > “Distinct Count” (available in Excel 2013 and later). This gives a distinct count without formulas.

Power Query (Get & Transform Data) also has a “Remove Duplicates” transformation. You can load your data, remove duplicates, and then count the rows—this is useful for one-off analysis or when you need to clean data before counting.

Frequently Asked Questions

How do I count unique values in a column with blanks?

Use =COUNTA(UNIQUE(A2:A100)) in Excel 365—it automatically ignores blanks. In older Excel, use =SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100, A2:A100&"")).

Why does my SUMPRODUCT formula return #DIV/0!?

Because your range contains blank cells. The formula divides 1 by the count of each value, and if a blank cell is counted, its count is 0, causing a division by zero. Add the condition (range<>"") to ignore blanks.

Can I count unique values with multiple conditions?

Yes. In Excel 365, use =COUNTA(UNIQUE(FILTER(range, (condition1)*(condition2)))). In older Excel, use a SUMPRODUCT formula with COUNTIFS, but note that it counts unique combinations of all criteria columns.

Is there a way to count unique values without formulas?

Yes. Use a PivotTable with the “Distinct Count” option (right-click the value field > Value Field Settings > Distinct Count). This works in Excel 2013 and later.

Does the UNIQUE function work in Excel 2019?

No. UNIQUE is only available in Excel 365, Excel 2021, and Excel for the web. In Excel 2019 and earlier, use the SUMPRODUCT or FREQUENCY formulas.

How do I count unique values that are numbers only?

Use =COUNTA(UNIQUE(FILTER(A2:A100, ISNUMBER(A2:A100)))) in Excel 365. In older versions, use =SUMPRODUCT((ISNUMBER(A2:A100))/COUNTIF(A2:A100, A2:A100))—but this still counts blanks as a unique value, so add (A2:A100<>"") if needed.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.