UNIQUE function in Excel

UNIQUE Function

I can’t even begin to count the number of times I have created a unique list in Excel.  I have performed it manually using the remove duplicates from the ribbon, Pivot Tables and using complex formulas, but that is now a thing of the past.  When Microsoft announced changes to Excel’s calculation engine in September 2018, they also announced a host of new functions, one of which is UNIQUE.

At the time of writing, the UNIQUE function is only available to those on a Microsoft 365 subscription.  It will not be available in Excel 2019 or earlier versions.

Download the example file
I recommend you download the files which support this post, as you’ll be able to work along with examples.  This is the best way to learn.  You’ll be able to see the solutions in action, plus the file will be useful for future reference.  The support files are available for FREE to newsletter subscribers.

Click below to subscribe and gain access to the subscriber area.  You will also receive:

  • My favorite tips and tricks direct to your inbox
  • Exclusive content (which is only available to subscribers)
  • FREE tools and downloads

Download Icon

If you’re already a subscriber, click here to log-in to the subscriber downloads area.

The filename for this post is 0032 UNIQUE function in Excel.zip 

Watch the video:

Watch the video on YouTube

The arguments of the UNIQUE function

The UNIQUE function is straightforward to apply, as shown by the animation below.

UNIQUE function basic example

UNIQUE has just three arguments. The last two are optional arguments and quite obscure, so you will only use them occasionally.

=UNIQUE(array, [by_col], [exactly_once])
  • array: the range or array to return values from.
  • [by_col]: an optional argument where FALSE = compare by row and TRUE = compare by column.  If excluded, the argument will default to FALSE.  The impact of this is demonstrated in Example 4.
  • [exactly_once]: This argument depends on your interpretation of the word unique.   If you want a list that includes only the items that appear once, then use TRUE.  If you want a list that contains one instance of each item (i.e., a distinct list), then use FALSE.  This is an optional argument and if excluded, will default to FALSE.  The impact of this is demonstrated in Example 1.

Download the 100 Excel Macros ebook

100 Excel Macros Book

  • Contains 100 Excel VBA macros
  • Learn VBA by following along with the example codes
  • Apply to your macros, automate Excel, save time.

Download the ebook today!

Click the button below to subscribe, you’ll gain access to the subscriber area in which you can download the ebook.

Download Icon (on mid-green background)

Examples of using the UNIQUE function

The following examples illustrate how to use the UNIQUE function.

Example 1 – The difference between unique and distinct

The last argument of the UNIQUE function determines if it returns a distinct or unique list.

Distinct list

UNIQUE function with distinct list

The formula in cell C3 is:

=UNIQUE(B3:B10)

As the third argument has not been used, exactly_once has defaulted to FALSE and therefore shows a list of distinct results.  Sally, Jack, Billy, Ryan, Chau and David all appear in cells B3-B10; therefore, we get a list of all those names.

Unique list (exactly once)

UNIQUE function with occurs_once

The formula in cell G3 is:

=UNIQUE(B3:B10,,TRUE)

The third argument is TRUE, therefore UNIQUE will return the results which appear only once in the array.  Sally, Billy, Ryan, and David all appear once within cells B3-B10.  However, Jack and Chau appear twice and are excluded from the result.

The difference between distinct and unique lists

When using the exactly_once argument, this is an important difference to understand:

  • FALSE or empty = a distinct list
  • TRUE = a list of items occurring only once

My guess is that in most situations, we will be using the distinct version of UNIQUE, which is the default option anyway.

Example 2 – UNIQUE linked to an Excel table

Example 2 shows how UNIQUE responds when linked to an Excel table.  When a new record is added, UNIQUE automatically expands to include the additional value in the spill range.  Notice that the spill range of the UNIQUE function updates as soon as new items are added to the table.

UNIQUE with table auto expands

The formula in cell G3 is:

=UNIQUE(tblExam[First])

As the UNIQUE function is referencing the entire column, when the column expands or retracts, so does the result of the formula.

Example 3 – UNIQUE across 2 columns

UNIQUE is not restricted to a single column.

Method 1

This returns the unique list and retains the same number of columns as included in the first argument.

UNIQUE function with multiple columns

The formula in cell G3 is:

=UNIQUE(B3:C10)

This includes the First and Last name columns in the array and returns both in the result.  One instance of Chau Yang has been excluded as it appears twice in the source list.

Method 2

The second method uses functionality from the new calculation engine to concatenate columns together before applying the UNIQUE function.

UNIQUE - values combined in a single column

The formula in cell G3 is:

=UNIQUE(B3:B10&" "&C3:C10)

Again, one instance of Chau Yang has been removed to provide a unique list within a single column.

Method 3

Sometimes we want a unique list with two columns that are not next to each other.  In this circumstance, we can use the CHOOSE function to reorder the columns.

UNIQUE CHOOSE to show columns in any order

The formula in cell G3 is:

=UNIQUE(CHOOSE({1,2},E3:E10,B3:B10))

By using CHOOSE, we have defined the first array as E3-E10 and the second array as B3-B10.  These are the ranges that have been returned within the spill range.

Example 4 – Using UNIQUE across columns

By default, Excel assumes UNIQUE should be applied on a vertical list.  However, it can also work on a horizontal list.

Horizontal list

UNIQUE across columns

In the example above, cell K3 contains the following formula.

=UNIQUE(D2:I2,TRUE)

The second argument of TRUE is used to tell the function that the data is in a horizontal format.

Use TRANSPOSE to convert horizontal & vertical (and vice versa)

If we had a vertical or horizontal list that we wanted to flip, we could use the TRANSPOSE function.

UNIQUE across columns and TRANSPOSE

The formula in cell K3 is:

=TRANSPOSE(UNIQUE(D2:I2,TRUE))

TRANSPOSE is used to change our horizontal UNIQUE list so the output is vertical.

Example 5 – Combining UNIQUE with SORT in a data validation list

Example 5 demonstrates how to combine the UNIQUE and SORT functions together.

UNIQUE and SORT together

The formula in cell G3 is:

=SORT(UNIQUE(C3:C10&", "&B3:B10))

The formula returns an alphabetically sorted unique list based on the last name and first names combined.

Often the purpose of a unique sorted list is for use within a data validation drop-down list.  To do this, we can use the # symbol after the cell reference to refer to the entire spill range.

UNIQUE and SORT in a datavalidation list

In the screenshot above, the formula is contained in cell G3.  Therefore =G3# has been used as the source for a data validation list.  When the spill range increases or decreases in size, so does the drop-down list.  It’s like magic!

Example 6 – Simple formula based Pivot Report

As a final example, we can create a simple Pivot Report using UNIQUE combined with some other common functions.

Pivot Report using UNIQUE

The formula in cell G3 is:

=UNIQUE(E3:E10)

This is the standard UNIQUE function applied to the Pass/Fail column.

The formula in cell H2 is:

=TRANSPOSE(UNIQUE(D3:D10))

TRANSPOSE switches the output of UNIQUE from displaying in rows to displaying in columns.  The 3 distinct dates in the Exam Date column are now listed as column headers.

The formula in H3 is:

=COUNTIFS(E3:E10,G3#,D3:D10,H2#)

The COUNTIFS function includes the # references, so it automatically spills in the same way as the cells it is dependent upon.

With 3 simple formulas we have created a complete report – amazing!.  Remember, if the source is an Excel table, the output will expand as new data is added – even more amazing!!

Want to learn more?

There is a lot to learn about dynamic arrays and the new functions.  Check out my other posts here to learn more:

Don’t forget:

If you’ve found this post useful, or if you have a better approach, then please leave a comment below.

Do you need help adapting this to your needs?

I’m guessing the examples in this post didn’t exactly meet your situation.  We all use Excel differently, so it’s impossible to write a post that will meet everybody’s needs.  By taking the time to understand the techniques and principles in this post (and elsewhere on this site) you should be able to adapt it to your needs.

But, if you’re still struggling you should:

  1. Read other blogs, or watch YouTube videos on the same topic.  You will benefit much more by discovering your own solutions.
  2. Ask the ‘Excel Ninja’ in your office.  It’s amazing what things other people know.
  3. Ask a question in a forum like Mr Excel, or the Microsoft Answers Community.  Remember, the people on these forums are generally giving their time for free.  So take care to craft your question, make sure it’s clear and concise.  List all the things you’ve tried, and provide screenshots, code segments and example workbooks.
  4. Use Excel Rescue, who are my consultancy partner.   They help by providing solutions to smaller Excel problems.

What next?
Don’t go yet, there is plenty more to learn on Excel Off The Grid.  Check out the latest posts:

Leave a Reply

Your email address will not be published. Required fields are marked *