formulastreak

Count unique values with a condition

Updated · Checked on a live sheet · Excel and Google Sheets

The formula

=COUNTA(UNIQUE(FILTER(D2:D13, E2:E13=I1))) counts the different agents who handled a ticket with the priority in I1. FILTER keeps the matching rows, UNIQUE removes repeats, COUNTA counts what's left. It needs Excel 2021 or later, Microsoft 365 or Google Sheets.

In general: =COUNTA(UNIQUE(FILTER(values, condition)))

Try it on a live sheet

How many different agents handled High priority tickets? · edit I2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultI2 = 3
ABCDEFGHI
1TicketOpenedClosedAgentPriorityRatingPriorityHigh
2T-1011 Apr 20262 Apr 2026MaraHigh5Agents3
3T-1021 Apr 20266 Apr 2026JonasLow3
4T-1032 Apr 20262 Apr 2026PriyaHigh4
5T-1043 Apr 20269 Apr 2026MaraMedium2
6T-1053 Apr 2026JonasHigh
7T-1066 Apr 20267 Apr 2026PriyaLow5
8T-1077 Apr 202610 Apr 2026MaraMedium4
9T-1088 Apr 20268 Apr 2026JonasHigh5
10T-1099 Apr 202615 Apr 2026PriyaMedium3
11T-11010 Apr 2026MaraLow
12T-11113 Apr 202614 Apr 2026JonasMedium4
13T-11214 Apr 202616 Apr 2026PriyaHigh5

I2 shows 3: Mara, Priya and Jonas each handled at least one High priority ticket, however many each one handled.

Why it works

Counts the cells in each different value of the rows of D2:D13 where E2:E13 is equal to I1 that aren't empty.

  1. 1. FILTER: Keeps the rows of D2:D13 where E2:E13 is equal to I1, and spills them into the cells below. If nothing matches, Excel shows #CALC!.
  2. 2. UNIQUE: Lists each different value in the result of step 1 once, and spills the list.
  3. 3. COUNTA: Counts the cells in the result of step 2 that aren't empty.

In any Excel version: SUMPRODUCT and COUNTIFS

Give each matching row 1 divided by how often its agent appears among matching rows, so each agent adds up to exactly 1: SUMPRODUCT((E2:E13=I1)/COUNTIFS(E2:E13, E2:E13, D2:D13, D2:D13)). It works without dynamic arrays and gives the same 3.

=SUMPRODUCT((E2:E13=I1)/COUNTIFS(E2:E13,E2:E13,D2:D13,D2:D13))

Two conditions

Multiply conditions inside FILTER: COUNTA(UNIQUE(FILTER(D2:D13, (E2:E13="High")*(F2:F13=5)))) counts agents with a five-star High priority ticket.

=COUNTA(UNIQUE(FILTER(D2:D13,(E2:E13="High")*(F2:F13=5))))

When you need it

“How many different customers bought this product?”, “how many agents worked on high-priority tickets?”, “how many stores sold something this week?”: distinct counts with a condition answer questions that a plain COUNTIFS can't, because COUNTIFS counts rows, not different values. They're common in dashboards and in job tests. Clean the values first (TRIM, consistent capitals), because “Mara” and “Mara ” count as two, and decide what an empty result should show.

In Google Sheets

Google Sheets has FILTER, UNIQUE and COUNTA, so the main formula works there. Sheets' FILTER returns #N/A when nothing matches, and COUNTA counts that error as 1; wrap it in IFNA if no match is possible.

Common mistakes

  • No match at all: in Excel, FILTER returns #CALC! and COUNTA counts the error as one value. Give FILTER a third argument and subtract, or check with COUNTIF first.

  • Spaces or different capitals making the same name look like two values: clean with TRIM first.

  • Using COUNTIF instead of COUNTIFS in the SUMPRODUCT version, which counts repeats across all rows, not just matching ones.

Practise UNIQUE on a live sheet

Lesson 33, Find duplicates (Unit 9, Data quality), has 4 graded exercises, checked instantly, with steps and hints when you're stuck. Pro