Advanced

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.

Книга1 - Excel
—☐✕
F2fx=СЧЁТЗ(УНИК(A2:A8))
ABCDEFG
1CustomerBranchAmountPurchases7
2AzizChilanzar450 000Distinct customers4
3DilnozaYunusabad1 200 000
4AzizChilanzar320 000
5JavokhirChilanzar780 000
6MalikaYunusabad150 000
7DilnozaChilanzar600 000
8AzizYunusabad900 000
9
Готово
7 purchases but only 4 distinct customers — with one formula

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.

Книга1 - Excel
—☐✕
C2fx=УНИК(A2:A8)
ABCD
1CustomerUNIQUE
2AzizAziz
3DilnozaDilnoza
4AzizJavokhir
5JavokhirMalika
6Malika
7Dilnoza
8Aziz
9
ГотовоКоличество: 4

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.

Книга1 - Excel
—☐✕
C2fx=1/B2
ABCD
1CustomerCOUNTIF1/COUNTIF
2Aziz30,33
3Dilnoza20,50
4Aziz30,33
5Javokhir11,00
6Malika11,00
7Dilnoza20,50
8Aziz30,33
9
ГотовоСреднее: 0,5714Количество: 7Сумма: 4
The calculation that happens “invisibly” inside the formula. Column C sums to 4 (Aziz: 0.33 × 3 = 1)

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.

Книга1 - Excel
—☐✕
ФайлГлавнаяВставкаРазметка страницыФормулыДанныеРецензированиеВидСправка
Сводная таблицаРекомендуемые сводные таблицыТаблица
Таблицы
Рисунки
Иллюстрации
Рекомендуемые диаграммыСводная диаграмма
Диаграммы
A1fxCustomer
ABCD
1CustomerBranchAmount
2AzizChilanzar450 000
3DilnozaYunusabad1 200 000
4AzizChilanzar320 000
5
ГотовоСреднее: 656666,6667Количество: 12Сумма: 1970000

2

Drag Branch to Rows and Customer to Values. Click the field in Values → Value Field Settings → Distinct Count.

Книга1 - Excel
—☐✕
B4fx4
ABCD
1Row LabelsDistinct Count of Customer
2Chilanzar3
3Yunusabad3
4Grand Total4
5
Готово
3 + 3 by branch, but 4 in total: Aziz and Dilnoza bought at both branches

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)).
Книга1 - Excel
—☐✕
D4fx=ЕСЛИ(СЧЁТЕСЛИМН($A$2:A4;A4;$B$2:B4;B4)=1;1;0)
ABCDEFG
1CustomerBranchFirst?Chilanzar:
2AzizChilanzar13
3DilnozaYunusabad1Yunusabad:
4AzizChilanzar03
5JavokhirChilanzar1
6MalikaYunusabad1
7DilnozaChilanzar1
8AzizYunusabad1
9
Готово
D4 = 0: Aziz’s second visit to Chilanzar. Each branch has 3 distinct customers

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.

Книга1 - Excel
—☐✕
Буфер обмена
Шрифт
Выравнивание
Число
Стили
Ячейки
Редактирование
✕✓fx
ABCDEFGHIJKLMNOPQRSTUVWX
1CustomerBranchAmountFirst?Distinct (SUM)
2AzizChilanzar450000Distinct (UNIQUE)
3DilnozaYunusabad1200000
4AzizChilanzar320000
5JavokhirChilanzar780000
6MalikaYunusabad150000
7DilnozaChilanzar600000
8AzizYunusabad900000
9
10
11
12
Лист1
Готово

Has ExcelLab been useful?

Support the project and help us release new lessons and exercises.

Support us
Previous

152 / 154