Sub topic 7
UNIQUE: remove duplicate values and rows
This chapter covers UNIQUE, the function that collapses repeated values or repeated rows into a list of distinct entries. It assumes you can enter formulas, use open-ended ranges such as B2:B, and read comparison operators. It also assumes you know that array formulas spill into neighboring cells. The spill rules were covered in an earlier chapter, and they apply here without change.
What UNIQUE does
UNIQUE takes a range and returns the same range with duplicates removed. The result is an array, so it spills down from the cell where you type the formula. The syntax is:
UNIQUE(range, [by_column], [exactly_once])rangeis the data to examine. It can be one column, several columns, or a row.by_columnis optional.FALSE(the default) compares rows.TRUEcompares columns.exactly_onceis optional.FALSE(the default) keeps one copy of every distinct item.TRUEkeeps only items that appear a single time.
The simplest use lists each region in a sales table once:
=UNIQUE(B2:B)If column B holds West, East, West, North, East, the formula returns West, East, North. Items appear in the order of their first appearance in the source. UNIQUE does not sort. If you want alphabetical output, wrap it in SORT, which a later section shows.
Values versus rows
When the range has one column, UNIQUE compares single values. When the range has several columns, it compares whole rows. A row counts as a duplicate only when every cell in it matches an earlier row.
Suppose A2:C holds Date, Region, and Amount. This formula removes only rows that are identical across all three columns:
=UNIQUE(A2:C)Two sales in the West for the same amount on different dates are both kept, because the dates differ. This behavior is the usual source of confusion. If you want one row per region, do not pass three columns. Pass column B alone, or build the unique list first and look up the other values afterward.
The diagram shows how the same data produces different results depending on the range you pass.
Worked example
Take this small table in A1:C8. Row 1 is the header.
| Date | Region | Amount |
|---|---|---|
| 2026-01-05 | West | 1200 |
| 2026-01-06 | East | 800 |
| 2026-01-07 | West | 1200 |
| 2026-01-08 | North | 450 |
| 2026-01-09 | East | 800 |
| 2026-01-10 | West | 2100 |
| 2026-01-11 | North | 450 |
Here is what three different formulas return.
| Formula | Result |
|---|---|
| `=UNIQUE(B2:B)` | West, East, North |
| `=UNIQUE(C2:C)` | 1200, 800, 450, 2100 |
| `=UNIQUE(A2:C)` | All 7 rows (every date is different) |
The last row of the table surprises many people. The amounts and regions repeat, but the dates do not, so no two full rows match. To detect repeated sales records, you would compare only the columns that define a duplicate, for example =UNIQUE(B2:C). That returns West/1200, East/800, North/450, and West/2100.
Notice that the range for the last formula starts at column B. You can pass any contiguous block, so choosing the right columns is how you define what "duplicate" means.
Open-ended ranges and blank cells
Using B2:B rather than B2:B100 lets the formula pick up new rows automatically. There is a side effect. The open-ended range includes empty cells below your data, and UNIQUE treats a blank as a value. The output then contains one extra empty cell at the end of the list.
Often this is harmless, but it can break a count or a dropdown source. Remove it by filtering out blanks first:
=UNIQUE(FILTER(B2:B, B2:B<>""))Here FILTER keeps only non-blank cells, and UNIQUE then works on that clean list. This pattern is common enough that it is worth using by default whenever the source range is open-ended.
Case, spaces, and data types
UNIQUE ignores letter case when it compares text. "west", "West", and "WEST" are treated as the same item, and the first one it meets is the one it returns.
It does not ignore spaces. "West" and "West " (with a trailing space) are different values, and both appear in the output. If your list contains near-duplicates that look identical, clean the text first:
=UNIQUE(ARRAYFORMULA(TRIM(B2:B)))TRIM removes leading and trailing spaces, and ARRAYFORMULA applies it to every cell in the range. Without ARRAYFORMULA, TRIM would return only one cell.
Data types matter too. The number 5 and the text "5" are different values. Numbers imported from other systems sometimes arrive as text, and then a column shows what looks like duplicates that UNIQUE refuses to merge. A quick check is to see whether the values align to the left of their cells, which usually indicates text.
UNIQUE options: by_column and exactly_once
exactly_once
The third argument changes the question from "what are the distinct items?" to "which items occur only once?" With exactly_once set to TRUE, any item that appears two or more times is dropped entirely, rather than being reduced to one copy.
=UNIQUE(B2:B, FALSE, TRUE)Using the example table, West appears three times, East twice, and North twice. No region appears exactly once, so the formula would produce no results. For the amount column, 2100 is the only amount that appears once, so =UNIQUE(C2:C, FALSE, TRUE) returns 2100.
This option is useful for finding one-off entries, such as customers who ordered only one time or IDs that were typed once and may contain typos.
Be careful about the empty case. When nothing qualifies, UNIQUE can return #N/A, as FILTER does. If the sheet needs to stay readable, wrap the formula:
=IFERROR(UNIQUE(C2:C, FALSE, TRUE), "No one-off values")by_column
The second argument rotates the comparison. When by_column is TRUE, UNIQUE looks across columns instead of down rows. Use it when your data is laid out horizontally, for example monthly labels in a header row that repeat.
=UNIQUE(A1:L1, TRUE)This compares the columns of A1:L1 and returns the distinct ones as a horizontal array. You will use this option much less often than the default, because most tables store records as rows.
Finding duplicates instead of removing them
UNIQUE removes duplicates, but a common task is the opposite: show which values are duplicated. A direct approach uses COUNTIF inside FILTER:
=UNIQUE(FILTER(B2:B, COUNTIF(B2:B, B2:B)>1))COUNTIF(B2:B, B2:B) counts how many times each value occurs and returns an array of counts. FILTER keeps the values whose count is above 1, and UNIQUE reduces them to one copy each. For the example table, it returns West, East, and North. Blank cells in an open-ended range can cause trouble here, so use a bounded range or add a blank check when the data is large.
Combining UNIQUE with SORT and FILTER
Because the output of UNIQUE is an array, you can pass it directly into other array functions. Functions run from the innermost outward, so read the formula from the inside.
=SORT(UNIQUE(FILTER(B2:B, C2:C>=1000)), 1, TRUE)FILTERkeeps regions whose amount is at least 1000.UNIQUEremoves repeated regions from that list.SORTorders the survivors alphabetically.
The order of nesting changes the result. Filtering before removing duplicates means you only deduplicate rows that qualify. Reversing it would deduplicate first and then try to filter a list that no longer lines up with column C, which gives a size mismatch error. As a rule, filter first, deduplicate second, and sort last.
Common mistakes
- Passing too many columns.
UNIQUE(A2:C)compares whole rows. If you wanted distinct regions, passB2:B. - Expecting sorted output.
UNIQUEpreserves first-appearance order. AddSORTif order matters. - Blocked spill range.
UNIQUEneeds empty cells below and beside the formula. Any value in the way produces a#REF!error that says the array result was not expanded. Clear the blocking cells. - Hidden spaces and text numbers. Values that look the same but differ in spacing or type are kept as separate items. Clean them with
TRIMor convert them withVALUE. - Confusing the two flags.
by_columnchanges direction.exactly_oncechanges which items survive. They are independent, so you can set either one without the other, but you must supply the earlier argument to reach the later one.
Practice
Exercise
A2:C holds Date, Region, and Amount. Column B contains "West", "west", and "West " (with a trailing space) in different rows. What does =UNIQUE(B2:B) return for these three entries, and how would you make it return one entry?
Show answer
It returns two entries: "West" (which also covers "west", because UNIQUE ignores case) and "West " (the trailing space makes it a different value). To get a single entry, trim the text first with =UNIQUE(ARRAYFORMULA(TRIM(B2:B))).
Exercise
Write a formula that lists, in alphabetical order, every region in B2:B that appears exactly once, and shows "None" if there are no such regions.
Show answer
=IFERROR(SORT(UNIQUE(B2:B, FALSE, TRUE), 1, TRUE), "None")