When using the unique function on an entire column, which value will be included in the results?

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 example file for this post.  Then you’ll be able to work along with examples and see the solution in action, plus the file will be useful for future reference.


Download the file: 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 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.

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

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)

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.

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.

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.

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.

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

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.

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.

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.

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.

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:

About the author

Hey, I’m Mark, and I run Excel Off The Grid.

My parents tell me that at the age of 7 I declared I was going to become a qualified accountant. I was either psychic or had no imagination, as that is exactly what happened. However, it wasn't until I was 35 that my journey really began.

In 2015, I started a new job, for which I was regularly working after 10pm. As a result, I rarely saw my children during the week. So, I started searching for the secrets to automating Excel. I discovered that by building a small number of simple tools, I could combine them together in different ways to automate nearly all my regular tasks. This meant I could work less hours (and I got pay raises!). Today, I teach these techniques to other professionals in our training program so they too can spend less time at work (and more time with their children and doing the things they love).

Do you need help adapting this post to your needs?

I'm guessing the examples in this post don't exactly match 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:

Última postagem

Tag