Using the UNIQUE Function

by Allen Wyatt
(last updated January 29, 2022)


Danny is unclear on how the UNIQUE worksheet function is used. He questions whether it only works with numbers, or will it work with text. He is particularly interested in how many characters in text values it might compare.

The UNIQUE function was added in the version of Excel provided with Microsoft 365. It is one of the rather unique (no pun intended) database functions now available in Excel. It is designed to analyze a range of cells and return the unique values in that range. It will work with any primary data type that Excel supports—numbers, text, dates, times, etc.

This is the syntax of the UNIQUE function:

UNIQUE(Range, Direction, ExactlyOnce)

According to this syntax, the UNIQUE function can use up to 3 parameters. Only one of those parameters is mandatory, however, and that is the Range parameter. This one indicates the range of cells you want UNIQUE to evaluate. The function returns an array of values, so that it spills over into whatever cells are available beneath the cell in which the function is used.

If the Range is a single column, then the unique values in that column are returned. When evaluating text values, UNIQUE doesn't pay attention to whether the text is uppercase or lowercase; it is all treated the same. Plus, length of the text is not a factor.

If the Range you specify is multiple columns (such as A2:B19), then UNIQUE analyzes the range as if it were a single column. For instance, if A6:B6 is "Frank, 12," and A12:B12 is "Frank, 41," then UNIQUE includes rows for both in what it returns—the key isn't on the uniqueness of the first column, but on the total uniqueness of all columns, considered together.

This understanding of the way that the Range parameter is understood can come in handy. Let's say that you have a list of names, with the last name being in column A and the first name being in column B. There are duplicates in the list, but you want the unique names to be determined. You could, if desired, derive the unique values in this way:

=UNIQUE(B2:B49&" "&A2:A49)

What gets returned is the unique names, in the form of first name, space, last name. If you prefer to have them with last name first, you could just as easily have used this variation:

=UNIQUE(A2:A49&", "&B2:B49)

You could even take it a step further and sort the names by wrapping the whole thing in the SORT function:

=SORT(UNIQUE(A2:A49&", "&B2:B49))

Back to the UNIQUE function, however. The second parameter (Direction) can be either True or False. The default for this parameter is False, which means that you are evaluating values downward, in a single column (or in an aggregated column, as described earlier). If you want to evaluate values across a row, you would set this parameter to True, as shown here:


The third parameter (ExactlyOnce) is the really interesting parameter. Like the Direction parameter, ExactlyOnce can be either True or False. The ExactlyOnce parameter also defaults to False, which means that all unique values are returned from the Range. If you set this parameter to True, however, then UNIQUE returns values from the Range that occur only once in that range.

As an example, let's say you had a bunch of transactions in the range A1:K1459. The first row is for column headers, and column A contains an account number for each transaction. These transactions are for the last six months, and your boss wants you to figure out which accounts made only a single transaction during that time so that you can offer them a special incentive to purchase again. You could use the following formula to determine the desired accounts:


You end up with just those account numbers you need—the ones that purchased only once during the last six months.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12835) applies to Microsoft Excel Excel in Office 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Default Cell Movement when Deleting

Delete a cell or a range of cells, and Excel needs to figure out how to rearrange the void left by the deletion. You can ...

Discover More

Limiting Directories in the FILENAME Field

When you use the FILENAME field in a document, it can include the full path name that leads to your file. This might be ...

Discover More

Turning Off the Date and Time Shown in a Comment

When you add a comment to a document, Word helpfully includes the date and time that the comment was added. If you don't ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Median of Selected Numbers

Need to find a median value in a series of values? It's easy with the MEDIAN function. What isn't as easy is to derive ...

Discover More

Calculating the Day of the Year

Need to know what day of the year a certain date is? You can figure it out easily using the formulas in this tip.

Discover More

Modifying Proper Capitalization

The PROPER worksheet function is used to change the case of text so that the first letter of each word is capitalized. If ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 5?

2022-01-30 16:34:57


Another good asset for this formula is the addition of the filter function to remove (or include) unwanted values. In my file, I have a column where we have the DIN number (unique ID in Canada for Drug Identification Number). The first row contains the header name "DIN" which I don't want to sort but If you don't include the first row in the formula you get an issue when you add a line at row 2 (and get a big mess in an inventory). Some product don't have a DIN (If they are a raw material item or R&D product). I also have empty lines in back-up which contain no value at all. The filter function remove the header row, the empty values and the non-DIN product (flagged "N/A"). DIN is a 8 digit number with leading zero(s). (e.g. 00258964)

=SORT(UNIQUE(FILTER($O$1:$O$1648,($O$1:$O$1648<>"N/A") * ($O$1:$O$1648<>"")*(RIGHT($O$1:$O$1648,3)<>"DIN"))))

this formula made me save hours of sorting, cutting, and pasting (and sometimes redoing cause of mistakes)

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.