Lesson 64 of 92 · Free Excel Course
Excel · Excel function reference
Excel UNIQUE Function: Syntax, Examples and Common Errors
How the Excel UNIQUE function lists distinct values, values that appear exactly once and unique rows, with SORT, FILTER and COUNTA examples and error fixes.
The UNIQUE function returns a list of the different values in a range, each one once. Give it a column with repeats and it hands back a clean list that updates by itself when the data changes. It can also return only the values that appear exactly once, or compare whole rows instead of single cells. The result is a dynamic array, so it spills down into as many cells as it needs. UNIQUE works in Excel for Microsoft 365 (Windows and Mac), Excel 2024, Excel 2021, Excel for the web and the Excel apps for iPad, iPhone and Android. Excel 2019 and earlier don't have it.
Syntax
=UNIQUE(array, [by_col], [exactly_once])
| Argument | Required? | What it does |
|---|---|---|
| array | Required | The range or array to pull unique values from. It can be one column, one row, or several columns at once. |
| by_col | Optional | How to compare. FALSE or left out (the default) compares rows with each other and returns unique rows. TRUE compares columns and returns unique columns, for data laid out across a row. |
| exactly_once | Optional | FALSE or left out (the default) returns every distinct value. TRUE returns only the values that occur exactly one time. |
To skip an optional argument, leave its comma in place: =UNIQUE(A2:A12,,TRUE) keeps by_col at its default and sets exactly_once to TRUE. Type the formula in one cell only and press Enter; Excel fills the cells below with the results.
Examples
1. Customers who came in only once (Microsoft's example). A car-service shop wants to call people who never came back. Setting exactly_once to TRUE returns the three names that appear a single time.
| A | B | C | |
|---|---|---|---|
| 1 | Customer Name | Service Type | Date |
| 2 | Fife, Grant | Tire rotation | 01/01/19 |
| 3 | Pruitt, Barbara | Oil change | 03/05/19 |
| 4 | Horn, Frances | 30k mile service | 03/08/19 |
| 5 | Barrett, Alicia | 30k mile service | 03/10/19 |
| 6 | Barrett, Alicia | Brake pads | 03/15/19 |
| 7 | Larson, Lynn | Oil change | 04/13/19 |
| 8 | Pruitt, Barbara | Oil change | 05/06/19 |
| 9 | Snook, Anthony | Oil change | 05/14/19 |
| 10 | Snook, Anthony | Transmission flush | 05/25/19 |
| 11 | Horn, Frances | Brake pads | 06/29/19 |
| 12 | Brown, Charity | Tire rotation | 09/29/19 |
| 13 | |||
| 14 | One-Time Only Customers | ||
| 15 | Fife, Grant | ||
| 16 | Larson, Lynn | ||
| 17 | Brown, Charity |
That's the difference worth remembering: the plain formula gives the distinct list (7 names, repeats shown once), while exactly_once gives the one-timers (3 names).
2. A sorted product list. UNIQUE keeps values in the order it first meets them. Wrap it in SORT for A to Z. Notice that row 9 says "chair" in lower case: UNIQUE ignores case, so Chair appears only once, spelled the way it first appears.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Region | Product | Units | Sorted products | |
| 2 | West | Desk | 4 | Chair | |
| 3 | East | Chair | 10 | Desk | |
| 4 | West | Lamp | 3 | Lamp | |
| 5 | North | Desk | 2 | Shelf | |
| 6 | East | Desk | 5 | ||
| 7 | West | Desk | 1 | ||
| 8 | North | Lamp | 6 | ||
| 9 | East | chair | 2 | ||
| 10 | West | Shelf | 1 | ||
| 11 | East | Chair | 7 |
3. Unique rows across two columns. Give UNIQUE two columns and it compares whole rows. Seven region-and-product pairs come back; the repeated West/Desk and East/Chair rows appear once.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Region | Product | Region | Product | |
| 2 | West | Desk | West | Desk | |
| 3 | East | Chair | East | Chair | |
| 4 | West | Lamp | West | Lamp | |
| 5 | North | Desk | North | Desk | |
| 6 | East | Desk | East | Desk | |
| 7 | West | Desk | North | Lamp | |
| 8 | North | Lamp | West | Shelf | |
| 9 | East | chair | |||
| 10 | West | Shelf | |||
| 11 | East | Chair |
4. Unique values that meet a condition, and a distinct count. Put FILTER inside UNIQUE to narrow the list first. =UNIQUE(FILTER(B2:B11,A2:A11="East")) returns Chair and Desk, the products sold in the East. To count instead of list, wrap UNIQUE in COUNTA: =COUNTA(UNIQUE(A2:A11)) returns 3 regions.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Region | Product | East products | Regions | |
| 2 | West | Desk | Chair | 3 | |
| 3 | East | Chair | Desk | ||
| 4 | West | Lamp | |||
| 5 | North | Desk | |||
| 6 | East | Desk |
5. Data across a row. When labels run left to right, set by_col to TRUE. If B1:G1 holds Q1, Q2, Q1, Q3, Q2, Q4, then =UNIQUE(B1:G1,TRUE) spills Q1, Q2, Q3, Q4 across the row.
Use the result as a drop-down list. Because the list updates itself, it makes a good source for a drop-down list. Put =SORT(UNIQUE(B2:B11)) in E2, then in Data > Data Validation choose List and type =$E$2# as the source. The # (the spilled range operator) means "the whole spill", so new products show up in the drop-down automatically.
Common errors
| What you see | Why | Fix |
|---|---|---|
| #SPILL! | Something is in the cells the result needs (even a space), the cells are merged, or the formula sits inside an Excel table. Excel outlines the range it wants with a dashed border. | Clear or unmerge the blocking cells, or move the formula outside the table. |
| #CALC! | Excel can't return an empty list. exactly_once is TRUE but every value repeats, or the FILTER inside finds nothing. | Give FILTER its third argument: =UNIQUE(FILTER(B2:B11,A2:A11="South","None")) shows None. For exactly_once, wrap it: =IFERROR(UNIQUE(A2:A11,,TRUE),"None"). |
| #NAME? | Your Excel doesn't have UNIQUE (2019 or older), or the name is misspelled. | Use Remove Duplicates or Advanced Filter, or open the file in Microsoft 365 or Excel for the web. |
| A 0 at the end | The range includes an empty cell, which UNIQUE returns as 0. | Use exactly the filled rows, or =UNIQUE(FILTER(B2:B20,B2:B20<>"")). |
| #REF! | The formula reads another workbook that is now closed. Microsoft says linked UNIQUE formulas only work while both files are open. | Open the source workbook, or copy the data into this one. |
| "Duplicates" not merged | One copy has a trailing space, or a number stored as text. Case is not the problem: UNIQUE ignores it. | Clean the column with TRIM, or convert text numbers to real numbers. |
Related functions
- Find and remove duplicates: the full lesson on highlighting, flagging and deleting repeats, including Remove Duplicates.
- Sort and filter: SORT and FILTER, the two functions most often wrapped around UNIQUE.
- FREQUENCY function: counts unique numbers and works in older versions of Excel.
- COUNTIF, SUMIF and AVERAGEIF: count how many times each unique value appears, with
=COUNTIF(B2:B11,E2#).
Try it yourself
Download the practice workbook. The Practice sheet has the ten orders from the examples and yellow cells for a sorted product list, unique region-product rows, an exactly-once list, an East-only list, a distinct count and a by_col list of quarters across a row, plus a bonus drop-down that uses =$E$2#. The Answers sheet has the working formulas to check against.
Frequently asked questions
Is the UNIQUE function case sensitive?
No. UNIQUE treats Chair, chair and CHAIR as the same value and keeps whichever spelling it meets first. Extra spaces do count, though, so "Chair " with a trailing space is a different value. Clean the column with TRIM first.
What is the difference between distinct and unique in UNIQUE?
=UNIQUE(A2:A12) gives the distinct list: every value once, repeats included once. =UNIQUE(A2:A12,,TRUE) sets exactly_once to TRUE and gives only the values that appear one time in the whole list. Microsoft calls the second one the database meaning of unique.
How do I count unique values in Excel?
Wrap UNIQUE in COUNTA: =COUNTA(UNIQUE(A2:A11)) counts the distinct values. If the column has blank cells, filter them out first: =COUNTA(UNIQUE(FILTER(A2:A11,A2:A11<>""))). For a column of numbers in older Excel, the FREQUENCY function can do it too.
Why does UNIQUE show a 0 at the end of the list?
Your range includes at least one empty cell, and UNIQUE returns an empty cell as 0. Point the formula at the filled rows only, or remove blanks with FILTER: =UNIQUE(FILTER(B2:B20,B2:B20<>"")).
Which versions of Excel have the UNIQUE function?
Excel for Microsoft 365 (Windows and Mac), Excel 2024, Excel 2021, Excel for the web and the Excel mobile apps. Excel 2019 and older don't have it; the formula shows #NAME? there. Use Advanced Filter or Remove Duplicates instead, as shown in Find and remove duplicates.