Excel - UNIQUE Function



UNIQUE Function

The Excel UNIQUE function works seamlessly with dynamic arrays to retrieve all the unique items from the array or cell range of the field. It is combined with other Excel functions like SORT, CHOOSE, FILTER, etc, to compute complex expressions. For example, patients book multiple appointments for consultation and have numerous entries of the same patient name in the dataset. You can utilize the UNIQUE function to retrieve the list of unique patient names along with the appointments that have been scheduled.

Compatibility

This advanced Excel function is compatible with the following versions of Microsoft Excel −

  • Excel for Microsoft 365
  • Excel for Microsoft 365 for Mac
  • Excel for the web
  • Excel 2024
  • Excel 2024 for Mac
  • Excel 2021
  • Excel 2021 for Mac
  • Excel for iPad
  • Excel for iPhone
  • Excel for Android tablets
  • Excel for Android phones

Syntax

The syntax of UNIQUE function is as follows −

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

Arguments

You can use the following arguments with the UNIQUE function −

Argument Description Required / Optional
Array It specifies the cell range or array Required
by_col It denotes a logical value, either TRUE or FALSE. If it equals TRUE, the unique column will be extracted only after comparing different fields; otherwise, unique rows will be extracted only after comparing rows. Optional
exactly_once It specifies the logical value as either TRUE or FALSE. If it is set to TRUE, it returns the values that appear not more than once. Otherwise, the FALSE value retrieves every distinct item. Optional

Examples of UNIQUE Function

Practice the following example to learn the use of the UNIQUE function in Excel.

Example 1

The UNIQUE function in Excel is used to extract unique values from a range or array.

Step 1 − First, open a new worksheet in Microsoft Excel and consider the following dataset, comprising four columns named Series, Vegetable, Cost, and Sale, and enter the data in these columns as shown below image.

UNIQUE Function in Excel

Step 2 − Now, we must fetch the nonduplicate items from the given range B5:B13. To achieve this, enter the formula =UNIQUE(B5:B13) in the G5 cell as shown below −

UNIQUE Function in Excel 1

Step 3 − After that, press the Enter tab to populate the list of unique vegetable in a specified range.

UNIQUE Function in Excel 2

Step 4 − Moreover, the resultant array can be sorted through the SORT function, which is effectively used with the Unique function. Locate the pointer in the G4 cell and write the formula =SORT(UNIQUE(B5:B13)) as highlighted in below image −

UNIQUE Function in Excel 3

Step 5 − The sorted list of distinct Vegetables is displayed in the resultant array −

UNIQUE Function in Excel 4

Step 6 − Suppose users wish to fetch only those vegetables that occur more than two times. In this case, use this formula =UNIQUE(FILTER(B5:B13,COUNTIF(B5:B13,B5:B13)>2)) as shown in the below image.

UNIQUE Function in Excel 5

Step 7 − Press the Enter key to obtain the resultant value. Tomatoes are the only vegetable that occurs more than twice in the specified range B5:B13.

UNIQUE Function in Excel 6

The following error may occur while running the Unique function.

  • The #Spill! error would appear if the data is already in the resultant column or resultant row. Users should choose the designated empty column or row range to remove this error.
  • If users try to execute the Unique function in an older Excel version other than Excel 365, a #Name? Error may occur.

Example 2

Extract the set of UNIQUE rows using the UNIQUE function in Excel.

Solution

Step 1 − First, assume the sample dataset consists of three columns: Patient ID, Patient Name, and Consultation Time.

Extract the Set of UNIQUE Rows

Step 2 − After that, you may enter the formula =UNIQUE(B2:D9,FALSE,FALSE) in the F2 cell and hit the Enter button.

Extract the Set of UNIQUE Rows 1

Extract the Set of UNIQUE Rows 2

Therefore, the unique rows are showcased in the dynamic array using the UNIQUE function.

Extract the Set of UNIQUE Rows 3

If you intend to display rows that appear precisely once, you can enter the formula =UNIQUE(B2:D9,FALSE,TRUE) in the F2 cell.

Extract the Set of UNIQUE Rows 4

Therefore, the UNIQUE function will retrieve two identical rows.

Extract the Set of UNIQUE Rows 5

Download Practice Sheet

You can download and use the sample data sheet to practice the UNIQUE function.

Advertisements