Count unique values with SUMPRODUCT and COUNTIF, explained
Free, no login, no limit. Runs in your browser. Paste an Excel or Google Sheets formula and get it in plain English, step by step. Nothing you paste is sent anywhere.
In plain English
Adds up every value of 1 divided by the number of cells in A2:A11 whose value is equal to A2:A11, working on whole ranges at once.
Works in: all current Excel versions, Google Sheets
Where each function is taught
Explain this Excel formula, step by step
Inside out: the order the spreadsheet works it out.
- 1COUNTIF
=COUNTIF(A2:A11, A2:A11)= 1Counts the cells in
A2:A11whose value is equal toA2:A11.range A2:A11the cells to check criteria A2:A11what to count From the course:
Guide: SUMIFS: totals with conditions Lesson 20COUNTIFcounts the cells in a range that match a criteria. It takes every criteria style you know: text, comparisons in quotes, cells. - 2SUMPRODUCT
=SUMPRODUCT(1/COUNTIF(A2:A11, A2:A11))= 10Adds up every value of
1divided by the result of step 1, working on whole ranges at once.range1 1/COUNTIF(A2:A11, A2:A11)the first column of numbers From the course:
Guide: Clean up messy text Lesson 32SUMPRODUCTtakes ranges of the same size, multiplies them row by row and adds the results.
Try it on a sample sheet
We filled the cells your formula reads with sample numbers and put the formula in C2. Type your own values (text works too) and watch the result and the steps above update.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | ||||
| 2 | 47 | 10 | ||
| 3 | 84 | |||
| 4 | 31 | |||
| 5 | 68 | |||
| 6 | 15 | |||
| 7 | 52 | |||
| 8 | 89 | |||
| 9 | 36 | |||
| 10 | 73 | |||
| 11 | 20 |
What this formula does
COUNTIF with the whole range as its criteria returns, for each row, how many times that row's value appears. Dividing 1 by that count gives each copy a share: a value that appears twice gives 1/2 on each of its two rows. SUMPRODUCT adds all the shares, so each distinct value contributes exactly 1. A value that appears three times gives a third on each of its three rows, which again adds up to one. The total is therefore the number of different values, however often each repeats.
When to use it
Use it to count distinct values in versions without UNIQUE (Excel 2019 and older), or where you want one formula with no spill. It ignores case, like COUNTIF. If the range can contain blank cells, use the version below, which skips them instead of dividing by zero.
Common mistakes
- Blank cells in the range, which make COUNTIF return 0 and the division fail.
- Expecting case-sensitive counting: COUNTIF treats “mara” and “MARA” as the same.
Variations
- =SUMPRODUCT((A2:A11<>"")/COUNTIF(A2:A11,A2:A11&""))Skips blank cells.
- =COUNTA(UNIQUE(A2:A11))The same count in Excel 2021 or later and Google Sheets.
- =SUMPRODUCT((B2:B11="Pro")/COUNTIFS(A2:A11,A2:A11,B2:B11,B2:B11))Distinct emails among Pro sign-ups only.
Read next
Practise this in 5 minutes
Everything this formula uses is taught in Lesson 32: Numbers stored as text (Unit 8, Cleaning text at scale), on a live sheet with instant feedback. Pro
Open “Numbers stored as text”Need a quick reference? The formula cheat sheet is free to read and print.
How the formula explainer works
It reads your formula with the same engine that grades formulastreak's lessons, then describes each function in the order a spreadsheet calculates it: the innermost first. Every argument gets a name and a plain-English meaning, taken from the lesson that teaches that function.
Then it builds a small sample sheet around the cells your formula reads, so you can see what each step returns and change the numbers to test it. Nothing is uploaded: it all happens in this page.
Google Sheets formulas too
Most formulas are written the same way in Excel and Google Sheets, so the explainer reads both. Under each explanation it says which Excel versions and whether Google Sheets have every function the formula uses, from Microsoft's and Google's own function lists. Where the two differ, such as SORT's direction argument or functions Google Sheets doesn't have, the note says so.
Want to understand the errors instead? Try the Excel error decoder, or read the formula guides.
Popular formulas, explained
- IFERROR with VLOOKUP, explained
=IFERROR(VLOOKUP(F2,$A$2:$C$9,3,FALSE),"Not found") - INDEX MATCH, explained
=INDEX($C$2:$C$9,MATCH(F2,$A$2:$A$9,0)) - INDEX MATCH MATCH (two-way lookup), explained
=INDEX(C2:E9,MATCH(I1,A2:A9,0),MATCH(I2,C1:E1,0)) - SUMIFS between two dates, explained
=SUMIFS(D2:D20,A2:A20,">="&H1,A2:A20,"<="&H2) - IF with AND, explained
=IF(AND(B2>=100,C2="Yes"),"Bonus","No bonus") - XLOOKUP with a not-found message, explained
=XLOOKUP(G2,A2:A9,C2:C9,"Missing") - COUNTIF to flag duplicates, explained
=COUNTIF($A$2:$A$11,A2)>1 - Count unique values with SUMPRODUCT and COUNTIF, explained
=SUMPRODUCT(1/COUNTIF(A2:A11,A2:A11)) - Nested IF for grades, explained
=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))) - SORT with FILTER, explained
=SORT(FILTER(A2:C20,C2:C20>1000),3,-1)
Questions
Which formulas can it explain?+
Any formula written for Excel or Google Sheets: it reads cell references, ranges, operators, text, nested functions, LET and LAMBDA. It describes about 150 functions in detail. If it meets a function it doesn't know yet, it says so and still explains the rest.
Does my formula leave my computer?+
No. The explanation and the sample sheet run entirely in your browser. Nothing you paste is sent to our server.
Why does it explain the formula inside-out?+
That's the order a spreadsheet works it out: the innermost functions first, then the functions that use their results. Reading it in that order makes long formulas much easier to follow.
Does it work for formulas from another sheet or workbook?+
Yes. References like Prices!A2:C9 are explained without the sheet name. Excel table references like Table1[Amount] aren't supported yet.
Is it the same in Excel and Google Sheets?+
Most formulas are. Below each explanation you'll see which versions of Excel and whether Google Sheets support every function it uses.