BBampaa

Lessons › Excel & Google Sheets

Excel & Google Sheets lesson

UNIQUE and counting distinct

Nine orders, but only three different locations: Lagos, Abuja and Accra. It's SQL's COUNT(DISTINCT location).

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

COUNTA counts every order. UNIQUE keeps each location once, so COUNTA(UNIQUE(...)) counts the different locations:

=COUNTA(UNIQUE(C2:C10))

Typed into cell I3 of this sheet:

OrderDayLocationProductQtyRevenueReportAnswer
O101MonLagosEarbuds270Orders
O102MonAbujaCharger115Locations
O103TueLagosPhone case324Products
O104WedLagosEarbuds135Days with orders
O105WedAbujaEarbuds4140
O106ThuLagosCharger230
O107FriAbujaPhone case540
O108FriLagosEarbuds3105
O109FriAccraEarbuds270

Key points

UNIQUELists each value once. UNIQUE(C2:C10) gives Lagos, Abuja, Accra.
COUNTA(UNIQUE(...))Counts the different values: 3 locations. Like COUNT(DISTINCT) in SQL.
Plain COUNTACounts every row, repeats and all: 9 orders. Use it for how many orders, not how many different.

Put together: =COUNTA(UNIQUE(C2:C10)). UNIQUE works in Google Sheets and Excel 365; older Excel doesn't have it.

Practice

Try each one in your head first, then open the answer.

1. In I3, count the different locations.
=COUNTA(UNIQUE(C2:C10))
2. In I2, count the orders.
=COUNTA(A2:A10)
3. In I4, count the different products.
=COUNTA(UNIQUE(D2:D10))
4. In I5, count how many different days had orders.
=COUNTA(UNIQUE(B2:B10))

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed