Sums and Counts

How to Count Unique Values in Excel

Learn how to count unique values in Excel with UNIQUE in newer versions, a SUMPRODUCT formula for older ones, and how blanks and case affect the count.

On this page
  1. Count distinct values with UNIQUE
  2. Older versions: SUMPRODUCT and COUNTIF
  3. Count unique values that meet a condition
  4. Use a pivot table or Remove Duplicates
  5. What can change the count
  6. Lists versus counts

Count distinct values with UNIQUE

In Excel 2021 and Microsoft 365, UNIQUE returns each distinct value once. Wrapping it in COUNTA counts them:

=COUNTA(UNIQUE(FILTER(A2:A100, A2:A100<>"")))

Here is how the pieces work. FILTER keeps only the non-blank cells in A2:A100. UNIQUE then removes repeats, and COUNTA counts what’s left. Without FILTER, a blank cell in the range can come through as 0 and be counted as an extra value.

Older versions: SUMPRODUCT and COUNTIF

Excel 2019 and earlier don’t have UNIQUE. This formula gives the same count without it:

=SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100, A2:A100&""))

Each non-blank cell contributes 1 divided by the number of times its value appears. A value that appears three times adds 1/3 three times, which totals 1. Blank cells contribute 0. The &“” part stops blank cells from causing a divide-by-zero error.

Count unique values that meet a condition

To count the unique customers in one region, filter the list first. Here column A holds customer names and column B holds the region:

=COUNTA(UNIQUE(FILTER(A2:A100, (B2:B100="East")*(A2:A100<>""))))

The multiplication means both tests must pass, so blank names are left out.

Use a pivot table or Remove Duplicates

Without formulas, add the field to a pivot table’s Rows area. Each distinct value appears once, so the number of rows in the pivot is the count. A row labeled (blank) may appear if the column has empty cells, so check for it.

Data, then Remove Duplicates, removes repeated rows from the data itself. Copy the list somewhere else first, then count what remains.

What can change the count

  • Letter case. UNIQUE and COUNTIF aren’t case-sensitive, so “Apple” and “apple” count as one value.
  • Extra spaces. “East” and “East “ are different values. Clean the data with TRIM, as described in remove extra spaces in excel formula.
  • Blanks. Empty cells are counted unless you filter them out, as the formulas above do.

The FILTER step in these formulas works the same way it does in how to use filter function in excel.

Lists versus counts

If you want the list of distinct values rather than the number, that’s a different task. In Microsoft 365 and Excel 2021, UNIQUE on its own returns the list, so an excel formula to remove duplicates can be as short as =UNIQUE(A2:A100). The count is simply the number of items in that list.

The complete guide to sums and counts

How to Sum and Count in Excel
Read the guide

Keep exploring

Guides from other topics

All topics →