“How many different products did each region sell?” is a distinct count per group — trickier than a plain distinct count. Excel 365 does it with UNIQUE + FILTER; any version can with a SUMPRODUCT ratio trick.
The example
Orders by region and product. How many distinct products did West sell?
| A | B | |
|---|---|---|
| 1 | Region | Product |
| 2 | West | Widget |
| 3 | East | Widget |
| 4 | West | Gadget |
| 5 | West | Widget |
| 6 | West distinct products: | 2 |
The formula
Distinct products for West (Widget, Gadget — Widget appears twice but counts once):
How it works
Filter to the group first, then de-duplicate:
FILTER(B2:B5, A2:A5="West")returns just West’s products: {Widget, Gadget, Widget}.UNIQUE(…)collapses that to the distinct set: {Widget, Gadget}.COUNTA(…)counts them —2.- Repeat for each group, or build a full per-group table by feeding it each region label.
One formula for the whole table (365): =GROUPBY(A2:A100, B2:B100, COUNTA, , , , , TRUE) patterns vary — but a spilled UNIQUE region list beside per-region distinct counts gives a tidy summary.
Try it: interactive demo
Pick a region; see how many distinct products it has.
Variations
Legacy SUMPRODUCT ratio (any version)
Counts distinct items within a group without UNIQUE:
Distinct count of the whole column
No grouping:
Build a per-group table
Spill the region list, then count beside each:
Pitfalls & errors
Blanks inflate the count. An empty product cell becomes a “distinct” value. Filter them out: FILTER(B2:B5, (A2:A5="West")*(B2:B5<>"")).
The SUMPRODUCT ratio needs matching ranges and breaks on blanks (divide-by-zero). Guard blanks or use the 365 method.
UNIQUE/FILTER need Excel 365/2021. Older versions show #NAME? — use the SUMPRODUCT version or a PivotTable with “Distinct Count.”
Practice workbook
Frequently asked questions
How do I count distinct values by group in Excel?
How do I do a distinct count by group without UNIQUE?
How do I count distinct values for the whole column?
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