Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS

Excel Tutorial

Excel HOME Excel Introduction Excel Get Started Excel Overview Excel Syntax Excel Ranges Excel Fill Excel Move Cells Excel Add Cells Excel Delete Cells Excel Undo Redo Excel Formulas Excel Relative Reference Excel Absolute Reference Excel Arithmetic Operators Excel Parentheses Excel Functions

Excel Formatting

Excel Formatting Excel Format Painter Excel Format Colors Excel Format Fonts Excel Format Borders Excel Format Numbers Excel Format Grids Excel Format Settings

Excel Data Analysis

Excel Sort Excel Filter Excel Tables Excel Conditional Format Excel Highlight Cell Rules Excel Top Bottom Rules Excel Data Bars Excel Color Scales Excel Icon Sets Excel Manage Rules (CF) Excel Charts

Excel PivotTables

Excel PivotTable Intro Excel Create PivotTable Excel PivotTable Values Excel PivotTable Filter Excel PivotTable Group Excel Calculated Field Excel PivotChart

Excel Case

Case: Poke Mart Case: Poke Mart, Styling

Excel Functions

AND AVERAGE AVERAGEIF AVERAGEIFS CONCAT COUNT COUNTA COUNTBLANK COUNTIF COUNTIFS DATEDIF FILTER HLOOKUP IF IFERROR IFS INDEX INDEX MATCH LEFT LEN LOWER MATCH MAX MEDIAN MID MIN MODE NETWORKDAYS NPV OR PROPER RAND RIGHT ROUND SORT STDEV.P STDEV.S SUBSTITUTE SUM SUMIF SUMIFS SUMPRODUCT TEXTJOIN TODAY TRIM UNIQUE UPPER VLOOKUP XLOOKUP XOR

Excel How To

Convert Time to Seconds Difference Between Times NPV (Net Present Value) Remove Duplicates

Excel Cert

Excel Certificate

Excel Examples

Excel Exercises Excel Syllabus Excel Study Plan Excel Training

Excel References

Excel Keyboard Shortcuts


Excel UNIQUE Function


Share

UNIQUE Function

The UNIQUE function is a premade function in Excel, which returns a list of the different values in a range. Each value is listed only once.

For example, the Type 1 column in the table below has 20 cells, but only five different types. UNIQUE returns those five.

It is typed =UNIQUE and has the following parts:

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

Note: UNIQUE is available in Excel for Microsoft 365, Excel 2021, Excel 2024 and Excel for the web. It is not available in Excel 2019 or earlier. If you type it in an older version, you get a #NAME? error.

Note: The different parts of the function are separated by a symbol, like comma , or semicolon ;

The symbol depends on your Language Settings.

Array: The range to get the different values from.

By_col: Optional. FALSE compares rows, which is the default. TRUE compares columns, for data that goes across instead of down. You will rarely need it.

Exactly_once: Optional. FALSE returns every different value once, which is the default. TRUE returns only the values that appear exactly one time in the range.

How to use the UNIQUE function:

  1. Select a cell (H2)
  2. Type =UNIQUE
  3. Double click the UNIQUE command
  4. Mark the range to get the values from (C2:C21)
  5. Hit enter

Let's have a look at an example!

This is the same Pokemon table as on the XLOOKUP page. Copy it and paste it into cell A1 to follow along:

Example data

ABCDE
1ID#NameType 1Type 2Total
21BulbasaurGrassPoison318
32IvysaurGrassPoison405
43VenusaurGrassPoison525
54CharmanderFire309
65CharmeleonFire405
76CharizardFireFlying534
87SquirtleWater314
98WartortleWater405
109BlastoiseWater530
1110CaterpieBug195
1211MetapodBug205
1312ButterfreeBugFlying395
1413WeedleBugPoison195
1514KakunaBugPoison205
1615BeedrillBugPoison395
1716PidgeyNormalFlying251
1817PidgeottoNormalFlying349
1918PidgeotNormalFlying479
2019RattataNormal253
2120RaticateNormal413

Type the label Type 1 in H1.

Use the UNIQUE function to list the different Type 1 values. Type the formula in H2:

ABCDEFGH
1ID#NameType 1Type 2TotalType 1
21BulbasaurGrassPoison318Grass
32IvysaurGrassPoison405Fire
43VenusaurGrassPoison525Water
54CharmanderFire309Bug
65CharmeleonFire405Normal
76CharizardFireFlying534
87SquirtleWater314
98WartortleWater405
109BlastoiseWater530
1110CaterpieBug195
1211MetapodBug205
1312ButterfreeBugFlying395
1413WeedleBugPoison195
1514KakunaBugPoison205
1615BeedrillBugPoison395
1716PidgeyNormalFlying251
1817PidgeottoNormalFlying349
1918PidgeotNormalFlying479
2019RattataNormal253
2120RaticateNormal413
=UNIQUE(C2:C21)

UNIQUE goes through C2:C21 from top to bottom. It keeps each type the first time it appears, and skips it after that.

The result is Grass, Fire, Water, Bug and Normal, in the order they first appear in the table. The formula is typed only in H2, and the result spills into H2:H6.

Note: The cells that the result spills into must be empty. If they are not, UNIQUE returns a #SPILL! error.

Note: UNIQUE is not case-sensitive. Fire and fire count as the same value.



Count the Unique Values

To count how many different types there are, use COUNTA on the result.

Type the label Number of types in J1, and this formula in J2:

HIJ
1Type 1Number of types
2Grass5
3Fire
4Water
5Bug
6Normal
=COUNTA(H2#)

H2# is a spill reference. The # after the cell means "the whole result that spills from H2". Here that is H2:H6, so COUNTA returns 5.

If you mark the spill range with the mouse while you type a formula, Excel writes the # for you.

Why not just use H2:H6? If a new type is added to the table, the UNIQUE list grows by one row. H2# includes the new row by itself. A fixed range like H2:H6 would miss it.

You can also count in one cell, without the list. =COUNTA(UNIQUE(C2:C21)) also returns 5.


Values That Appear Only Once

Set exactly_once to TRUE to list only the values that appear one time in the range.

When the array has more than one column, UNIQUE compares whole rows. Use C2:D21 to look at Type 1 and Type 2 together, and find the type combinations that only one Pokemon has.

Type the labels Type 1 in L1 and Type 2 in M1, and this formula in L2:

LM
1Type 1Type 2
2FireFlying
3BugFlying
=UNIQUE(C2:D21, FALSE, TRUE)

Charizard is the only Pokemon that is Fire and Flying, and Butterfree is the only one that is Bug and Flying. All the other combinations are shared. Grass and Poison, for example, belong to Bulbasaur, Ivysaur and Venusaur.

FALSE is the by_col part. You must fill it in, so that TRUE lands in the exactly_once part.

Note: If no value appears exactly once, UNIQUE returns a #CALC! error. =UNIQUE(C2:C21, FALSE, TRUE) gives #CALC!, because every Type 1 appears at least three times.


Skip Empty Cells

If the range has empty cells, UNIQUE returns them as 0. Type 2 is empty for nine of the Pokemon.

Change the label in H1 to Type 2, and the formula in H2 to this one:

HIJ
1Type 2Number of types
2Poison3
30
4Flying
=UNIQUE(D2:D21)

All the empty cells together show up as one 0, in H3. COUNTA in J2 counts the 0 as a type, and returns 3.

To skip the empty cells, use FILTER inside UNIQUE. FILTER removes the empty cells first, and UNIQUE lists what is left:

HIJ
1Type 2Number of types
2Poison2
3Flying
4
=UNIQUE(FILTER(D2:D21, D2:D21<>""))

The <> sign means "not equal to", and "" is an empty text. So D2:D21<>"" keeps only the cells that are not empty.


Sort the Unique List

UNIQUE keeps the order of the table. To sort the list from A to Z, put UNIQUE inside the SORT function.

Change the label in H1 back to Type 1, and the formula in H2 to this one:

HIJ
1Type 1Number of types
2Bug5
3Fire
4Grass
5Normal
6Water
=SORT(UNIQUE(C2:C21))

UNIQUE finds the five types, and SORT puts them in order from A to Z.


UNIQUE vs Remove Duplicates

The Remove Duplicates command deletes the duplicate rows from the data itself. UNIQUE leaves the data as it is, and makes a new list that updates by itself.

Read more on the How to Remove Duplicates page. To color duplicate or unique values instead, see the Duplicate and Unique Values rule in conditional formatting.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.