ElyxAI
formulas

How to Count Unique Values

Excel 2016Excel 2019Excel 365

Learn how to count unique values in Excel using formulas like SUMPRODUCT and COUNTIF. This essential skill helps you analyze data quickly, eliminate duplicates from reporting, and gain insights into customer lists, product inventories, or survey responses. Master multiple techniques to handle various data scenarios efficiently.

Why This Matters

Counting unique values is critical for data quality audits, reporting, and decision-making across business functions. It saves time compared to manual counting and prevents errors in analysis.

Prerequisites

  • Basic understanding of Excel formulas and cell references
  • Familiarity with COUNTIF function
  • Data organized in a single column or range

Step-by-Step Instructions

1

Prepare your data

Organize your data in a single column without blank rows in the middle. Select the data range you want to analyze (e.g., A2:A100).

2

Click an empty cell for the result

Choose a cell outside your data range where you want the unique count to appear (e.g., cell D2).

3

Enter the SUMPRODUCT formula

Type the formula: =SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100)). Press Enter to execute and get your unique count result.

4

Verify the result

Check the output number against your data visually or use Data > Filter to cross-verify unique entries are counted correctly.

5

Handle errors if present

If you see #DIV/0! error, your data contains blanks; use =SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")) instead.

Alternative Methods

SUMPRODUCT with COUNTIF (with blanks handling)

Use =SUMPRODUCT(--(COUNTIF(A$2:A2,A2:A100)=1)) to count unique values while excluding blanks automatically.

Pivot Table method

Insert > Pivot Table, drag your field to Rows area, and count distinct entries visually without formulas.

Remove Duplicates (Data Tools)

Use Data > Remove Duplicates to create a clean list, then count remaining rows; useful for quick visual verification.

Tips & Tricks

  • Always ensure your data range is continuous with no gaps to avoid formula errors.
  • Use absolute references ($A$2:$A$100) if you plan to copy the formula to other cells.
  • For large datasets, SUMPRODUCT may calculate slower; consider Pivot Tables for better performance.
  • Test with a small dataset first to confirm the formula works before applying to thousands of rows.

Pro Tips

  • Combine UNIQUE() function (Excel 365) with COUNTA for the fastest modern approach: =COUNTA(UNIQUE(A2:A100)).
  • For case-insensitive counting, wrap your range with UPPER or LOWER inside COUNTIF to treat 'Apple' and 'APPLE' as the same value.
  • Use conditional formatting to highlight duplicates first, then verify your unique count matches your visual inspection.

Troubleshooting

Formula returns 0 when I expect a higher number

Check for leading/trailing spaces in your data using TRIM function. Apply TRIM to your range first, then recount with the formula.

SUMPRODUCT formula is very slow with 100k+ rows

Switch to the UNIQUE() function in Excel 365 or use a Pivot Table instead for better performance on large datasets.

Counting includes blank cells as unique

Add a condition to exclude blanks: =SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&""),1*(A2:A100<>"")).

Related Excel Formulas

Frequently Asked Questions

Can I count unique values across multiple columns?
Yes, but you need to concatenate the columns first using a helper column with =A2&B2&C2, then apply the SUMPRODUCT formula to that helper column.
What's the difference between UNIQUE() and SUMPRODUCT for counting?
UNIQUE() (Excel 365 only) is simpler and faster: =COUNTA(UNIQUE(A2:A100)). SUMPRODUCT works in older versions but is slower with large datasets.
How do I count unique values with criteria?
Use SUMPRODUCT with multiple conditions: =SUMPRODUCT((A2:A100="Apple")/COUNTIF(A2:A100,A2:A100&""),1*(A2:A100="Apple")) to count unique 'Apple' entries.
Does the formula work with text and numbers mixed?
Yes, SUMPRODUCT treats text and numbers as different values automatically, so '123' and 123 are counted separately.

This was one task. ElyxAI handles hundreds.

Sign up