How many different customers ordered in the East region? Count distinct values that also meet a condition — a SUMPRODUCT reciprocal trick does it without a pivot.
=SUMPRODUCT((region="East")*(MATCH(name®ion, name®ion, 0)=ROW(name)-ROW(firstcell)+1)).
The example
Distinct customers in the East region.
| A | B | |
|---|---|---|
| 1 | Region | Customer |
| 2 | East | Ann |
| 3 | East | Ann |
| 4 | East | Bo |
| 5 | Distinct East | 2 |
The formula
Distinct count with a filter:
How it works
The reciprocal trick, narrowed by a condition:
- Each matching row contributes
1 / (count of that name within East). - A name appearing 3 times adds
1/3three times = 1; so each distinct name counts once. - The
(region="East")factor zeroes out rows that don’t meet the condition. - SUMPRODUCT totals the contributions — the count of distinct names in East.
Excel 365 is far simpler: =COUNTA(UNIQUE(FILTER(name, region="East"))) — filter to the region, take the uniques, count them. The SUMPRODUCT version is for older Excel.
Try it: interactive demo
Lines “region,name”; count distinct in East.
Variations
365 version
Filter, unique, count:
Distinct overall
No condition:
Two conditions
Add another factor in SUMPRODUCT.
Pitfalls & errors
No blanks in the range. The reciprocal trick divides by COUNTIF, so an empty cell causes #DIV/0!. Filter blanks out.
Match the criteria in COUNTIFS. The denominator must count within the same condition, or the math is off.
365 is easier. UNIQUE+FILTER avoids the fragile reciprocal entirely.
Practice workbook
Frequently asked questions
How do I count distinct values with a condition in Excel?
Why does the SUMPRODUCT version error?
How do I count distinct values overall?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class