FormulaCraft

How to count distinct values without a pivot table in Excel and Google Sheets

Topic:Pivot-style summaries (formula approach)

Heads up: Excel and Google Sheets do this differently.

Excel
=SUMPRODUCT(1/COUNTIF(A2:A6,A2:A6))
Google Sheets
=COUNTUNIQUE(A2:A6)

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Place the values you want to count (possibly with duplicates) in A2:A6.
  2. 2In Excel, enter =SUMPRODUCT(1/COUNTIF(A2:A6,A2:A6)). COUNTIF returns how many times each value appears; 1/count gives each occurrence a fractional weight summing to 1 per distinct value.
  3. 3SUMPRODUCT adds all fractions, yielding the total distinct count.
  4. 4In Google Sheets, use =COUNTUNIQUE(A2:A6) for the same result with cleaner syntax.
  5. 5To count distinct values meeting a condition (e.g., Region = 'East'), use =SUMPRODUCT((B2:B6="East")/COUNTIFS(A2:A6,A2:A6,B2:B6,B2:B6)).

Tips

Need the Google Sheets version instead? Open Sheets variant in workspace →

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

Frequently asked

Why does SUMPRODUCT(1/COUNTIF) divide by zero?

If the range contains empty cells, COUNTIF returns 0 for them, causing division by zero. Add a blank check: =SUMPRODUCT((A2:A6<>"")*1/COUNTIF(A2:A6,A2:A6&"")).

How do I get a distinct count by group (like a pivot's Distinct Count in Values)?

Use =SUMPRODUCT((A2:A6="East")/COUNTIFS(B2:B6,B2:B6,A2:A6,A2:A6)) where A is the group and B is the value column.

Is COUNTUNIQUE available in Excel?

No. COUNTUNIQUE is Google Sheets only. In Excel use SUMPRODUCT(1/COUNTIF) or ROWS(UNIQUE(...)) in Excel 365.

More on Pivot-style summaries (formula approach)

See all →

Formulas used

Related tasks

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: