Going Stellar

Home/Google Sheets reference

Google Sheets function · Filter and sort

UNIQUE in Google Sheets: syntax and examples

UNIQUE removes duplicate rows from a range and spills the rest in order of first appearance. With a second and third argument it can compare columns instead of rows, or keep only values that appear exactly once. Comparison is case-sensitive and exact.

Syntax

UNIQUE(range, [by_column], [exactly_once])

Arguments

ArgumentTypeRequiredWhat it does
rangerangeyesThe range to deduplicate. Whole rows are compared.
by_columnbooleannoTRUE compares columns instead of rows. The default is FALSE.
exactly_oncebooleannoTRUE keeps only rows that appear one time. The default is FALSE.

Examples

The examples use this table, starting in A1:

RegionProductUnits
NorthLamp10
SouthChair4
NorthChair6
NorthLamp3
EastLamp8
=UNIQUE(A2:A6)

Result:

North
South
East

The distinct regions, in order of first appearance.

Run in a Google Sheet (English US locale) on .

=UNIQUE(A2:B6)

Result:

NorthLamp
SouthChair
NorthChair
EastLamp

Distinct region and product pairs. Two columns are compared together.

Run in a Google Sheet (English US locale) on .

=UNIQUE(A2:A6, FALSE, TRUE)

Result:

South
East

Only regions that appear exactly once.

Run in a Google Sheet (English US locale) on .

=SORT(UNIQUE(A2:A6))

Result:

East
North
South

Distinct regions in alphabetical order.

Run in a Google Sheet (English US locale) on .

=COUNTA(UNIQUE(A2:A6))

Result: 3

How many distinct regions there are.

Run in a Google Sheet (English US locale) on .

Common errors

  • Comparison is case-sensitive. "a" and "A" count as two different values.
  • A trailing space makes a different value. "a " is not the same as "a", so TRIM the data first.
  • UNIQUE with exactly_once set to TRUE returns #REF! when no row appears only once.
  • A blank cell is a value too. UNIQUE on x, blank, x returns two rows: x and an empty one.

Compared with Excel

Excel 365 has UNIQUE with the same three arguments.

Questions and answers

How do I list unique values in alphabetical order?

Wrap it: SORT(UNIQUE(A2:A6)). UNIQUE keeps order of first appearance, and SORT then orders the list.

Sources

  1. UNIQUE (Docs Editors Help)

Markdown version · All functions