List each value once with UNIQUE
Formulas that spill8 minPremium
Builds on Fill a range with one formula, and fix #SPILL! and Total by one condition with SUMIF.
An events coordinator in Chicago has a registration list with one row per guest, so each company appears as often as it sends people. The caterer wants the companies, each once, with a head count for each.
How it works
UNIQUE( returns each different value in array once, in the order it first appears. Given several columns, it compares whole rows, and two rows count as one only when every column matches. Capitals don't make values different, but spaces do, so "Boston" and "Boston " stay apart. With TRUE as the third argument, it returns only the values that appear exactly once.
Picture reading down the list with a pen, writing each value down the first time you meet it and skipping it after that.
The list spills, so other formulas can work along it with #. =COUNTIF( gives one count for each value in E2's list and grows or shrinks with it, and SUMIF does the same for totals. Wrap UNIQUE in SORT for a list from A to Z.
Example
A courier's log has the city of each delivery in A2:A11.
=SORT(UNIQUE(A2:A11))- Step 1: UNIQUE reads down
A2:A11and keeps the first Denver, the first Boulder and so on. - Step 2: SORT puts the five cities from A to Z, and the list spills down from C2.
- Step 3:
=COUNTIF(counts each city in the list, one count per row.A2:A11, C2#)
C2# gives one count per city and follows the list as it changes. In D2, =COUNTIF(A2:A11,C2#) returns 2.With this log, D3 shows 3 deliveries for Boulder and D5 shows 1 for Golden.
Common mistakes
=UNIQUE(starts on the header row, so "City" joins the list. Start below the headers.A1:A11) - "Denver" and "Denver " with a space at the end count as two cities. Clean the column first, or use
=UNIQUE(.TRIM( A2:A11)) =COUNTIF(filled down stops at the rows you filled. WithA2:A11, C2) C2#, the counts follow the list.=UNIQUE(leaves out every city that appears more than once. Leave TRUE out for one of each.A2:A11, , TRUE)
In short
=UNIQUE(lists each value once, in the order it first appears, andrange) =SORT(lists them A to Z.UNIQUE( range)) - A formula beside it that reads the list with
#, such as=SUMIF(, gives one figure per value.range, E2#, amounts) - Spaces make two values different, and capitals don't.
- TRUE as the third argument keeps only the values that appear exactly once.
Practice
Premium4 exercises: 3 formulas and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in