Skip to content

UNIQUE

Returns each distinct value or row of a range once, in the order it first appears.

Syntax

=UNIQUE(, , )

Dynamic arrays

Excel for Microsoft 365, Excel 2021 and later, and Excel for the web. Not available in Excel 2019 or earlier.

Try it

Edit the formula in E2 or change the inputs. The sheet recalculates as you type.

E2
A
B
C
D
E
F
1
Order
Region
Product
2
SO-1
North
Gloves
North
3
SO-2
South
Gloves
South
4
SO-3
North
Tape
East
5
SO-4
East
Gloves
West
6
SO-5
South
Gloves
Central
7
SO-6
North
Gloves
8
SO-7
East
Tape
9
SO-8
West
Gloves
10
SO-9
Central
Tape
11

E2 =UNIQUE(B2:B10) returns North; South; East; West; Central

How UNIQUE works

UNIQUE builds a list of the distinct items in a column: the regions in a sales log, the customers who ordered, the departments in a payroll export. It does what the Remove Duplicates button does, but without changing your data, and the list updates when the source does.

The three arguments

  • array is the range to scan. With one column you get a list of values. With several columns, UNIQUE treats each row as one item, so =UNIQUE(B2:C10) returns every different region and product pair.
  • by_col switches the comparison to columns. You will rarely need it. It is for data laid out across a row, such as a list of codes in B1:K1.
  • exactly_once changes the question. With FALSE you ask: which values are there? With TRUE you ask: which values appear only once? Use it to find one-off customers or unmatched entries. Setting it to TRUE isn't a way of getting a normal distinct list.

Distinct, not sorted

The results come back in order of first appearance. Wrap UNIQUE in SORT for an alphabetical list: =SORT(UNIQUE(B2:B10)).

Counting distinct values

UNIQUE with COUNTA or ROWS counts how many different values there are. =COUNTA(UNIQUE(B2:B10)) returns 5 for the data below. If part of the list is blank, count with ROWS(UNIQUE(FILTER(B2:B10,B2:B10<>""))) so the blank isn't counted.

Reading the result with #

The list spills down from the cell you typed in. To use the whole list in another formula, add # to the anchor cell. If E2 holds =UNIQUE(B2:B10), then =COUNTA(E2#) counts its items however many there are today. See FILTER for more on spill ranges and #SPILL!.

Matching rules

Text comparison ignores case, so "north" and "North" are the same item. Spaces count: "North" and "North " (with a trailing space) are different. If the list contains near-duplicates, clean the source with TRIM first: =UNIQUE(TRIM(B2:B10)).

A blank cell in the source comes back as 0 in the list. Filter blanks out first if that matters.

Compatibility

UNIQUE needs Microsoft 365, Excel 2021 or later, or Excel for the web. In earlier versions, use Data > Remove Duplicates on a copy of the data, or a PivotTable.

Arguments

array
The range or array to remove duplicates from. With several columns, UNIQUE compares whole rows.
by_coloptional
FALSE, the default, compares rows. TRUE compares columns, for data that runs across a sheet.
exactly_onceoptional
FALSE, the default, returns every distinct item once. TRUE returns only items that appear a single time in the data, and drops anything that is repeated. If none qualify, the result is #CALC!.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

A list of the regions in the log

E2 =UNIQUE(B2:B10)

Result: North; South; East; West; Central

Nine orders, five different regions, in the order each first appears.

E2
A
B
C
D
E
F
1
Order
Region
Product
2
SO-1
North
Gloves
North
3
SO-2
South
Gloves
South
4
SO-3
North
Tape
East
5
SO-4
East
Gloves
West
6
SO-5
South
Gloves
Central
7
SO-6
North
Gloves
8
SO-7
East
Tape
9
SO-8
West
Gloves
10
SO-9
Central
Tape
11

E2 =UNIQUE(B2:B10) returns North; South; East; West; Central

Example 2

Only the values that appear once

E2 =UNIQUE(B2:B10,,TRUE)

Result: West; Central

North, South and East each appear more than once, so they are dropped. West and Central appear exactly once. The empty second argument keeps the default of comparing rows.

E2
A
B
C
D
E
F
1
Order
Region
Product
2
SO-1
North
Gloves
West
3
SO-2
South
Gloves
Central
4
SO-3
North
Tape
5
SO-4
East
Gloves
6
SO-5
South
Gloves
7
SO-6
North
Gloves
8
SO-7
East
Tape
9
SO-8
West
Gloves
10
SO-9
Central
Tape
11

E2 =UNIQUE(B2:B10,,TRUE) returns West; Central

Example 3

Distinct combinations across two columns

E2 =UNIQUE(B2:C10)

Result: North, Gloves; South, Gloves; North, Tape; East, Gloves; East, Tape; West, Gloves; Central, Tape

A row is a duplicate only if both columns match an earlier row. The nine orders reduce to seven region and product pairs.

E2
A
B
C
D
E
F
1
Order
Region
Product
2
SO-1
North
Gloves
North
Gloves
3
SO-2
South
Gloves
South
Gloves
4
SO-3
North
Tape
North
Tape
5
SO-4
East
Gloves
East
Gloves
6
SO-5
South
Gloves
East
Tape
7
SO-6
North
Gloves
West
Gloves
8
SO-7
East
Tape
Central
Tape
9
SO-8
West
Gloves
10
SO-9
Central
Tape
11

E2 =UNIQUE(B2:C10) returns North, Gloves; South, Gloves; North, Tape; East, Gloves; East, Tape; West, Gloves; Central, Tape

Example 4

A sorted list of distinct values

E2 =SORT(UNIQUE(B2:B10))

Result: Central; East; North; South; West

UNIQUE returns the regions in the order they first appear. SORT puts them in alphabetical order.

E2
A
B
C
D
E
F
1
Order
Region
Product
2
SO-1
North
Gloves
Central
3
SO-2
South
Gloves
East
4
SO-3
North
Tape
North
5
SO-4
East
Gloves
South
6
SO-5
South
Gloves
West
7
SO-6
North
Gloves
8
SO-7
East
Tape
9
SO-8
West
Gloves
10
SO-9
Central
Tape
11

E2 =SORT(UNIQUE(B2:B10)) returns Central; East; North; South; West

Example 5

Count the distinct items by using # on the spill range

G2 =COUNTA(E2#)

Result: 5

E2# is the whole list that the formula in E2 returns. If a new region appears in the log, the list grows and the count follows.

G2
A
B
C
D
E
F
G
1
Order
Region
Product
2
SO-1
North
Gloves
North
5
3
SO-2
South
Gloves
South
4
SO-3
North
Tape
East
5
SO-4
East
Gloves
West
6
SO-5
South
Gloves
Central
7
SO-6
North
Gloves
8
SO-7
East
Tape
9
SO-8
West
Gloves
10
SO-9
Central
Tape
11

G2 =COUNTA(E2#) returns 5

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 3

In D2, list each ticket category once.

Answer in D2.

D2
A
B
C
D
E
F
G
H
I
1
Ticket
Category
2
T-01
Billing
3
T-02
Access
4
T-03
Billing
5
T-04
Network
6
T-05
Access
7
T-06
Billing
8
T-07
Hardware
9
T-08
Network
10
T-09
Billing
11
12

Common mistakes

  • A trailing space makes a different value: "North " is not "North". If the list shows what looks like a duplicate, run TRIM over the source with =UNIQUE(TRIM(B2:B10)).
  • The third argument does not mean "give me the distinct list". TRUE returns only items that occur once, and #CALC! when there are none. Leave it out for a normal distinct list.
  • Blank cells in the source show as 0 in the result. Filter them out first: =UNIQUE(FILTER(B2:B10,B2:B10<>"")).
  • Text is compared without regard to case, so "east" and "East" count as the same item and the first one found is kept.
  • Include a header row in array and the header is treated as a value. Start the range on the first data row.

Questions people ask

How do I count unique values in Excel?

Use `=COUNTA(UNIQUE(B2:B10))`, or `=ROWS(UNIQUE(B2:B10))`. If the range can contain blanks, filter them out inside UNIQUE so they are not counted as a value.

What does the third argument of UNIQUE do?

With `TRUE`, UNIQUE returns only the items that appear exactly once in the data. Items that appear twice or more are left out completely. It is not the same as a distinct list.

Is UNIQUE case-sensitive?

No. "north" and "North" are treated as the same value. To compare with case, you need a different approach, such as testing with EXACT.

Does UNIQUE sort the results?

No. Values come back in order of first appearance. Use `=SORT(UNIQUE(range))` for alphabetical order.

Why does UNIQUE return #CALC!?

It returned an empty result. That happens with `exactly_once` set to TRUE when every value is repeated, or when the source range is empty.

How is UNIQUE different from Remove Duplicates?

Remove Duplicates deletes rows from your data once. UNIQUE leaves the data alone and returns a live list that changes when the source does.

Learn UNIQUE in a real sheet.

UNIQUE is taught in Data analysis with formulas, lesson 12: UNIQUE: lists and distinct counts. Each lesson is a short, graded exercise like the one above.