Sub topic 8
UNIQUE Options: `by_column` and `exactly_once`
Assume you know how to enter formulas, use ranges such as A2:C100, and read Boolean conditions such as TRUE and FALSE. This chapter focuses on the optional arguments of UNIQUE, a Google Sheets function that returns distinct rows, columns, or values from a range.
The `UNIQUE` function
The basic syntax is:
=UNIQUE(range, [by_column], [exactly_once])The square brackets mean that the arguments are optional.
| Argument | Default | Meaning |
|---|---|---|
| `range` | Required | The cells to examine |
| `by_column` | `FALSE` | Compare rows when false, or columns when true |
| `exactly_once` | `FALSE` | Keep repeated values once when false, or keep only single-occurrence values when true |
With the default settings, UNIQUE removes duplicate rows while preserving the order of their first appearance.
Suppose A2:C6 contains this data:
| Region | Product | Sales |
|---|---|---|
| West | Basic | 400 |
| East | Pro | 900 |
| West | Basic | 400 |
| South | Pro | 700 |
| East | Pro | 900 |
This formula returns each complete row once:
=UNIQUE(A2:C6)The duplicate West, Basic, 400 row and duplicate East, Pro, 900 row are removed. A result that occupies multiple cells is an array result. Google Sheets spills it into the cells below and beside the formula.
Comparing columns with `by_column`
By default, UNIQUE compares rows. Set the second argument to TRUE when each column is the item you want to compare.
For example, if A1:D2 contains:
| Row | Column | Column | Column |
|---|---|---|---|
| Red | Blue | Red | Green |
| 10 | 20 | 10 | 30 |
This formula compares the columns:
=UNIQUE(A1:D2, TRUE)The third column is a duplicate of the first column, so it is removed. The result contains the first Red column, followed by Blue and Green.
The option is useful when data is arranged horizontally. For ordinary tables, where each record occupies a row, leave by_column as FALSE or omit it.
=UNIQUE(A2:C100, FALSE)Keeping values that appear exactly once
The third argument changes the meaning of “unique.” With the default FALSE, a repeated value appears once in the output. With TRUE, a value appears only if it occurs one time in the input.
If B2:B7 contains:
West
East
West
South
East
NorthUse this formula:
=UNIQUE(B2:B7, FALSE, TRUE)The result is:
South
NorthWest and East are excluded because each appears twice.
This distinction matters:
=UNIQUE(B2:B7)means “list each value once.”=UNIQUE(B2:B7, FALSE, TRUE)means “list values whose total count is one.”
exactly_once applies to the complete item being compared. If you use a multi-column range, Google Sheets checks complete rows. Two rows with the same region but different products are different rows.
=UNIQUE(A2:C100, FALSE, TRUE)This returns only complete records that occur exactly once.
Combining `UNIQUE` with other functions
You can first filter data and then remove duplicates. The inner function runs first:
=UNIQUE(FILTER(B2:B100, C2:C100>=1000))This returns each region with sales of at least 1,000 once. To list regions that meet the condition exactly once, use:
=UNIQUE(FILTER(B2:B100, C2:C100>=1000), FALSE, TRUE)The input to UNIQUE is the filtered result, so “exactly once” is measured only among rows that passed the filter.
Exercise
Column A contains A, B, A, and C. What formula returns only the values that occur exactly once?
Show answer
=UNIQUE(A1:A4, FALSE, TRUE), which returns B and C.