FxFormula Drills

The UNIQUE function

UNIQUE returns each distinct value once, in the order it first appears, and spills the list. Wrap it in ROWS when you want the count of distinct values instead of the list. The third argument TRUE keeps only values that occur exactly once. Remove Duplicates on the Data tab deletes extra copies in place and does not update when new rows arrive. UNIQUE needs Excel 2021, Microsoft 365, or Google Sheets.

Syntax

UNIQUE

UNIQUE(array, [by_col], [exactly_once])

array is the list. by_col FALSE, the default, looks down rows. TRUE looks across columns. exactly_once TRUE returns only entries that appear a single time. The default FALSE returns every distinct entry, including ones that were repeated.

ROWS around UNIQUE

ROWS(UNIQUE(array))

ROWS counts the spilled list, which is the number of distinct values. The drill uses this so the answer fits in one cell.

Remove Duplicates

Data > Remove Duplicates (a command, not a function)

Deletes duplicate rows from the range you select, keeping the first copy. It is permanent until you undo it. It does not spill and it does not refresh.

Comparison

QuestionUNIQUEROWS of UNIQUERemove Duplicates
ResultA spilled list of distinct valuesA countThe original range, with later copies deleted
RepeatsKept once, by defaultCounted onceDeleted after the first
Values that appear onceIncluded. The third argument can keep only theseIncluded in the countKept, because they were never duplicated
UpdatesYesYesNo
VersionsExcel 2021, Microsoft 365, Google SheetsSame, plus ROWS which is olderDesktop Excel, including older versions

Worked examples

Distinct regions

The list is East, West, East, North, West, East. Three regions appear. East and West repeat. North appears once.

Six region labels, three distinct names.
RowA
1Region
2East
3West
4East
5North
6West
7East
  • =UNIQUE(A2:A7) → East
  • C3 spilled → West
  • C4 spilled → North
  • =ROWS(UNIQUE(A2:A7)) → 3
  • =UNIQUE(A2:A7,,TRUE) → North

UNIQUE lists East, then West, then North. That is first-seen order, not alphabetical order. ROWS of that list is 3, which is the distinct count the drill asks for. The third argument TRUE drops East and West because they appear more than once, leaving North.

When to use which

Use UNIQUE for a live set of categories

A dropdown of regions, or a checklist of products that actually occur in the data, should change when someone adds a region. UNIQUE does that. Sort it with SORT if you need alphabetical order. SORT is in the same Excel versions as UNIQUE.

Use ROWS(UNIQUE(...)) for the count

The question 'how many different regions' is a count, not a list. The premium drill grades that count. COUNTIF would need one criterion per region and would not notice a new region.

Use Remove Duplicates for a one-time cleanup

A pasted contact list that should lose duplicate emails before you import it is a command, not a formula. Keep a copy of the original. The command will not drop a duplicate that arrives tomorrow.

Common mistakes

Counting rows with COUNTA instead of distinct values

COUNTA of the six labels is 6. The distinct count is 3. COUNTA does not collapse repeats.

Expecting alphabetical order

East appears before West in the result because East is first in the sheet, not because of the alphabet. Wrap UNIQUE in SORT if the order should be sorted.

The third argument when you wanted ordinary distinct values

exactly_once TRUE removed East and West in the example and left only North. Leave that argument out, or pass FALSE, when repeats should still appear once.

Numbers stored as text looking distinct

The text 04 and the number 4 are different values to UNIQUE. Clean the column first if they should be one entry.

Versions and compatibility

UNIQUE is in Excel 2021, Excel 2024, Microsoft 365, Excel for the web, and Google Sheets. It is not in Excel 2019. Remove Duplicates is the desktop command for those older files, with the limitation that it is not live.

ROWS is much older and is in Google Sheets. ROWS(UNIQUE(...)) therefore needs UNIQUE more than it needs a new ROWS.

Google Sheets has UNIQUE as well. It does not have Excel's Remove Duplicates command under that name. The function is the portable piece.

Practice on Formula Drills

Free drills are open with no account. Premium drills show the problem to everyone and grade the sheet for subscribers.

Free exercises

Premium exercises

Function pages

FAQ

Does UNIQUE keep the first copy or the last?

The distinct list is in first-seen order. You get one row per value. It does not tell you which later duplicate it ignored, because the result is the value, not the original row number.

Can UNIQUE look across a header row?

Pass TRUE as the second argument to compare columns instead of rows. The default FALSE is the vertical list in the example.

How do I get distinct pairs, such as region and product?

Pass both columns as the array, UNIQUE(A2:B7). A pair is unique when the combination is unique. Two East rows with different products both remain.

What if the spill lands on another formula?

Excel returns #SPILL! and shows nothing until those cells are empty. Put the formula where there is room below it, or use ROWS so the result is a single cell.