How to count unique values in Excel: COUNTA(UNIQUE), SUMPRODUCT(1/COUNTIF) and Distinct Count
Count how many different values a list has in Excel: COUNTA(UNIQUE()), SUMPRODUCT(1/COUNTIF()) for any version, conditional counts, PivotTable Distinct Count, and the blank-cell trap.
The October sales log has 7 purchases. But the manager asks something else: how many different customers bought? If Aziz came three times, he’s still one customer. COUNTA doesn’t help here — it counts rows, not people.
Keep two ideas apart:
- Distinct values — each value once: Aziz, Dilnoza, Javokhir, Malika → 4.
- Values occurring only once (unique) — no repeats: Javokhir, Malika → 2.
Day to day you usually need the first. Below are ways to count both in different Excel versions.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Customer | Branch | Amount | Purchases | 7 | ||
| 2 | Aziz | Chilanzar | 450 000 | Distinct customers | 4 | ||
| 3 | Dilnoza | Yunusabad | 1 200 000 | ||||
| 4 | Aziz | Chilanzar | 320 000 | ||||
| 5 | Javokhir | Chilanzar | 780 000 | ||||
| 6 | Malika | Yunusabad | 150 000 | ||||
| 7 | Dilnoza | Chilanzar | 600 000 | ||||
| 8 | Aziz | Yunusabad | 900 000 | ||||
| 9 |
Method 1: COUNTA(UNIQUE()) — Excel 2021 and 365
1
First see what UNIQUE returns: type =УНИК(A2:A8) in an empty cell. Each customer spills down once.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Customer | UNIQUE | ||
| 2 | Aziz | Aziz | ||
| 3 | Dilnoza | Dilnoza | ||
| 4 | Aziz | Javokhir | ||
| 5 | Javokhir | Malika | ||
| 6 | Malika | |||
| 7 | Dilnoza | |||
| 8 | Aziz | |||
| 9 |
2
Now wrap it in COUNTA: =СЧЁТЗ(УНИК(A2:A8)) → 4. You don’t have to show the list — it is built inside the formula and counted right away.
3
To count values that occur exactly once: =СЧЁТЗ(УНИК(A2:A8;;ИСТИНА)) → 2 (Javokhir and Malika). The third argument TRUE means “exactly once”.
Method 2: SUMPRODUCT(1/COUNTIF()) — any version
1
The classic formula: =СУММПРОИЗВ(1/СЧЁТЕСЛИ(A2:A8;A2:A8)) → 4. How does it work? For each row it counts “how many times does this customer appear” and divides 1 by that. Aziz appears 3 times — 1/3 in each of his rows, 1 in total. Dilnoza twice — 1/2 + 1/2 = 1. Every customer adds exactly 1 to the sum.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Customer | COUNTIF | 1/COUNTIF | |
| 2 | Aziz | 3 | 0,33 | |
| 3 | Dilnoza | 2 | 0,50 | |
| 4 | Aziz | 3 | 0,33 | |
| 5 | Javokhir | 1 | 1,00 | |
| 6 | Malika | 1 | 1,00 | |
| 7 | Dilnoza | 2 | 0,50 | |
| 8 | Aziz | 3 | 0,33 | |
| 9 |
2
The single-cell formula builds exactly this column C in memory and adds it up. SUMPRODUCT handles arrays without Ctrl+Shift+Enter, which is why it works all the way back to Excel 2007.
3
On big tables (tens of thousands of rows) it slows down: the whole column is recounted for every row. In that case use UNIQUE or a PivotTable.
Method 3: Distinct Count in a PivotTable (no formulas)
1
Click inside the table and go to Вставка → Сводная таблица. In the dialog be sure to tick Add this data to the Data Model — Distinct Count only appears then.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Customer | Branch | Amount | |
| 2 | Aziz | Chilanzar | 450 000 | |
| 3 | Dilnoza | Yunusabad | 1 200 000 | |
| 4 | Aziz | Chilanzar | 320 000 | |
| 5 |
2
Drag Branch to Rows and Customer to Values. Click the field in Values → Value Field Settings → Distinct Count.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Row Labels | Distinct Count of Customer | ||
| 2 | Chilanzar | 3 | ||
| 3 | Yunusabad | 3 | ||
| 4 | Grand Total | 4 | ||
| 5 |
Pro level: unique counts with a condition
Question: “How many different customers did the Chilanzar branch have?”
- Excel 365:
=СЧЁТЗ(УНИК(ФИЛЬТР(A2:A8;B2:B8="Chilanzar")))→ 3. FILTER keeps Chilanzar rows, UNIQUE removes repeats, COUNTA counts. - Older versions:
=СУММПРОИЗВ((B2:B8="Chilanzar")/СЧЁТЕСЛИМН(A2:A8;A2:A8;B2:B8;B2:B8))— the same idea, applied to customer+branch pairs. - The clearest way — a “first occurrence” flag. In a helper column:
=ЕСЛИ(СЧЁТЕСЛИМН($A$2:A2;A2;$B$2:B2;B2)=1;1;0)— 1 in the row where the customer first appears at that branch, 0 afterwards. Then a plain=СУММЕСЛИ(B2:B8;"Chilanzar";D2:D8). Works in any version, is fast and easy to audit. - Distinct pairs across two columns:
=СЧЁТЗ(УНИК(A2:A8&"-"&B2:B8)).
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Customer | Branch | First? | Chilanzar: | |||
| 2 | Aziz | Chilanzar | 1 | 3 | |||
| 3 | Dilnoza | Yunusabad | 1 | Yunusabad: | |||
| 4 | Aziz | Chilanzar | 0 | 3 | |||
| 5 | Javokhir | Chilanzar | 1 | ||||
| 6 | Malika | Yunusabad | 1 | ||||
| 7 | Dilnoza | Chilanzar | 1 | ||||
| 8 | Aziz | Yunusabad | 1 | ||||
| 9 |
Try it in the simulator
Type =ЕСЛИ(СЧЁТЕСЛИ($A$2:A2;A2)=1;1;0) in D2 and fill down to D8 — each customer’s first purchase gets a 1. Type =СУММ(D2:D8) in F1 and =СЧЁТЗ(УНИК(A2:A8)) in F2: both should give 4.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Customer | Branch | Amount | First? | Distinct (SUM) | |||||||||||||||||||
| 2 | Aziz | Chilanzar | 450000 | Distinct (UNIQUE) | ||||||||||||||||||||
| 3 | Dilnoza | Yunusabad | 1200000 | |||||||||||||||||||||
| 4 | Aziz | Chilanzar | 320000 | |||||||||||||||||||||
| 5 | Javokhir | Chilanzar | 780000 | |||||||||||||||||||||
| 6 | Malika | Yunusabad | 150000 | |||||||||||||||||||||
| 7 | Dilnoza | Chilanzar | 600000 | |||||||||||||||||||||
| 8 | Aziz | Yunusabad | 900000 | |||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 | ||||||||||||||||||||||||
| 11 | ||||||||||||||||||||||||
| 12 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.