The UNIQUE function
UNIQUE removes the repeats from a list and returns each value once, in the order it first appears. The result spills into the cells below, and grows or shrinks as the data changes.
Give it more than one column and it returns each distinct *row*. It's the usual first step in a summary table: list the categories with UNIQUE, then total each one with SUMIF.
=UNIQUE(array, [by_col], [exactly_once])
Arguments
- array
- The range to take distinct values (or distinct rows) from.
- by_coloptional
- TRUE to compare columns instead of rows. Leave it out for an ordinary list down a column.
- exactly_onceoptional
- TRUE to return only values that appear exactly once. Leave it out to return every distinct value.
Try it
=UNIQUE(B2:B7) in E2. Leeds, York and Hull spill into E2:E4. The lower-case york counts as the same town, so it isn't listed again.
E2
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Order | Town | Amount | Towns | ||
| 2 | 1041 | Leeds | £120 | Leeds | ||
| 3 | 1042 | York | £45 | York | ||
| 4 | 1043 | Leeds | £300 | Hull | ||
| 5 | 1044 | Hull | £80 | |||
| 6 | 1045 | york | £60 | |||
| 7 | 1046 | Leeds | £210 | |||
| 8 | ||||||
| 9 |
Edit the formula in E2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =ROWS(UNIQUE(B2:B7)) | 3 | Count the distinct towns by counting the rows UNIQUE returns. |
| =TEXTJOIN(", ",TRUE,UNIQUE(B2:B7)) | Leeds, York, Hull | Join the list into one cell, in first-seen order. |
| =TEXTJOIN(", ",TRUE,UNIQUE(B2:B7,,TRUE)) | Hull | With exactly_once TRUE, only towns that appear once are returned. |
| =TEXTJOIN(", ",TRUE,SORT(UNIQUE(B2:B7))) | Hull, Leeds, York | Wrap UNIQUE in SORT for an alphabetical list. |
Tips
- Build a summary:
=UNIQUE(B2:B7)in E2, then=SUMIF(B2:B7,E2#,C2:C7)next to it. The#refers to the whole spilled list. - Wrap in SORT to put the list in order:
=SORT(UNIQUE(B2:B7)). - Leave empty cells below the formula so the list has room to grow.
Common mistakes
- "Leeds" appears twice in the list.One of them has a hidden space. Clean the data with TRIM, or use
UNIQUE(TRIM(B2:B7)). - You get #SPILL!.Something is in the cells below the formula. Clear them so the list can spill.
- A blank row in the data shows as 0 in the list.UNIQUE returns the empty cell too. Filter it out first:
=UNIQUE(FILTER(B2:B20,B2:B20<>"")).
In Google Sheets
Google Sheets' UNIQUE is case-sensitive, so York and york would both be listed there. Wrap the range in LOWER or PROPER first (inside ARRAYFORMULA) if case shouldn't matter.
Practise UNIQUE with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.