Tabellab
Excel formulas

UNIQUE function in Excel: distinct lists, distinct counts and sorting

The UNIQUE function returns every value of a range once, in the order it first appears, and spills the list into the cells below. =UNIQUE(A2:A13) turns twelve order lines into the 6 distinct customers who placed them, =ROWS(UNIQUE(A2:A13)) counts them, and =UNIQUE(A2:A13,FALSE,TRUE) finds the 2 customers who ordered exactly once. This guide covers the syntax, distinct counts, sorting, several columns, UNIQUE with FILTER and a summary table that grows by itself.

Updated 21 Oct 2026 5 min read By Tabellab team

The UNIQUE syntax

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

  • array: the range to de-duplicate, one column or several.
  • by_col: FALSE (the default) compares rows, TRUE compares columns. You rarely need TRUE.
  • exactly_once: FALSE (the default) returns every distinct value, TRUE only the values that appear exactly once.

UNIQUE is a dynamic array function, available in Microsoft 365, Excel 2021 and later and Excel for the web. The result spills, so keep the cells below the formula empty. The comparison is not case-sensitive: "Harbor Cafe" and "harbor cafe" count as one.

A distinct list, sorted A to Z

=UNIQUE(A2:A13) returns Harbor Cafe, Pine Deli, Oak Bistro, Mill Bakery, Fern Grill and Sage Kitchen: first-appearance order, which is the order of the first order each customer placed. For an alphabetical list wrap it in SORT: =SORT(UNIQUE(A2:A13)) starts with Fern Grill and ends with Sage Kitchen. =SORT(UNIQUE(A2:A13),,-1) sorts Z to A.

Worked example: twelve order lines, distinct customers and a summary

Rows 2 to 13 are the order lines. Rows 16 to 21 are the distinct customers with their orders and revenue, and column D is the same list sorted A to Z.

Worked example: twelve order lines, distinct customers and a summary
ABCD
1CustomerTeaRegionAmount
2Harbor CafeGreen teaNorth240
3Pine DeliBlack teaSouth180
4Oak BistroGreen teaNorth320
5Harbor CafeOolongNorth150
6Mill BakeryBlack teaEast210
7Pine DeliGreen teaSouth260
8Fern GrillOolongEast90
9Harbor CafeBlack teaNorth300
10Sage KitchenGreen teaWest130
11Oak BistroOolongNorth170
12Pine DeliBlack teaSouth220
13Mill BakeryGreen teaEast190
14
15UNIQUE(A2:A13)OrdersRevenueSORT(UNIQUE())
16Harbor Cafe3690Fern Grill
17Pine Deli3660Harbor Cafe
18Oak Bistro2490Mill Bakery
19Mill Bakery2400Oak Bistro
20Fern Grill190Pine Deli
21Sage Kitchen1130Sage Kitchen
22
23Distinct customers: ROWS(UNIQUE())6
24Same count, pre-365 way: SUMPRODUCT(1/COUNTIF())6
25Customers who ordered exactly once2
26First of them (exactly_once = TRUE)Fern Grill
27Distinct teas3
28Distinct customer and tea pairs: UNIQUE(A2:B13)11
29Distinct customers in the North region2
30Check: revenue of the summary = all orders0
Key formulas
  • A16=INDEX(UNIQUE($A$2:$A$13),1)1st distinct customer (in Excel: =UNIQUE(A2:A13) spills)
  • C16=SUMIFS($D$2:$D$13,$A$2:$A$13,A16)Revenue per customer (in Excel: =SUMIFS(D2:D13,A2:A13,A16#))
  • D23=ROWS(UNIQUE(A2:A13))Distinct count
  • D25=ROWS(UNIQUE(A2:A13,FALSE,TRUE))Exactly once
  • D29=ROWS(UNIQUE(FILTER(A2:A13,C2:C13="North")))Distinct values of a filtered subset

Fictional order data. In Excel each UNIQUE formula spills its whole list from one cell; the grid uses INDEX(UNIQUE(…),k) so each value can be shown and checked in its own cell.

Count distinct values

A distinct list has as many rows as there are distinct values, so =ROWS(UNIQUE(A2:A13)) returns 6. If the list has already spilled into A16, =ROWS(A16#) or =COUNTA(A16#) gives the same answer. Before dynamic arrays, the usual trick was =SUMPRODUCT(1/COUNTIF(A2:A13,A2:A13)): every customer that appears three times contributes 3 × 1/3 = 1. It also returns 6 and still works in old versions, but it is slow on large ranges and fails with blank cells (division by zero).

Values that appear exactly once

Set the third argument to TRUE: =UNIQUE(A2:A13,FALSE,TRUE) returns only Fern Grill and Sage Kitchen, the 2 customers with a single order. That is a different question from "distinct": distinct means "each value once", exactly once means "values without duplicates". It is useful for one-off customers who need a follow-up call, or for codes that should repeat but do not.

UNIQUE on several columns, and with FILTER

With more than one column, UNIQUE compares whole rows. =UNIQUE(A2:B13) returns each customer and tea combination once: 11 pairs, because only Pine Deli and Black tea appears twice. To get the distinct values of a subset, filter first: =UNIQUE(FILTER(A2:A13,C2:C13="North")) lists the 2 customers from the North region (Harbor Cafe and Oak Bistro), even though North has five order lines. The FILTER guide shows how to combine several criteria in that step.

A summary table that grows by itself

Put =UNIQUE(A2:A13) in A16 and refer to the spilled list with A16#: =COUNTIF(A2:A13,A16#) counts the orders and =SUMIFS(D2:D13,A2:A13,A16#) totals the revenue per customer, each as one formula that spills next to the list. Harbor Cafe has 3 orders worth 690 and Pine Deli 3 orders worth 660. When a new customer appears in the data, the list and both columns get one row longer without any formula being copied. The check in the last row proves that the summary adds up to the total of all orders. The same pattern with SUMIFS is the basis of most dynamic reports.

How the example shows the spilled lists

In Excel, A16 would hold the single formula =UNIQUE(A2:A13) and the six names would spill into A16:A21, with B16 and C16 spilling next to it. The example grid shows every value in its own checked cell, so A16 to A21 use =INDEX(UNIQUE($A$2:$A$13),k) for the k-th distinct value and B and C use a normal COUNTIF and SUMIFS per row. The values are the same as the spilled result.

Common mistakes

  • Cells in the way of the spill. A value below the formula blocks the list and shows #SPILL!. Leave enough empty rows for new values.
  • Blank cells in the range. UNIQUE returns an empty cell as a 0 in the list. Filter the blanks out first: =UNIQUE(FILTER(A2:A100,A2:A100<>"")).
  • Expecting a sorted result. UNIQUE keeps the first-appearance order. Wrap it in SORT for an alphabetical list.
  • Mixing up distinct and exactly once. UNIQUE(A2:A13,FALSE,TRUE) drops every value that appears more than once. It is not the distinct list.
  • Hidden spaces and spelling variants. "Pine Deli" and "Pine Deli " count as two customers. Clean the column with TRIM before counting.
  • Referring to A16:A21 instead of A16#. A fixed range does not grow with the list. The spill reference does.

Frequently asked questions

How do I count unique values in Excel?

Use =ROWS(UNIQUE(A2:A13)) for the number of distinct values, or =ROWS(UNIQUE(A2:A13,FALSE,TRUE)) for the values that appear exactly once. In versions without UNIQUE, =SUMPRODUCT(1/COUNTIF(A2:A13,A2:A13)) counts distinct values as long as there are no blank cells.

What is the difference between distinct and unique values?

Distinct values are every value listed once, which is what UNIQUE returns by default. Unique in the strict sense means values that occur only once, which UNIQUE returns when the third argument exactly_once is TRUE.

Is the UNIQUE function case-sensitive?

No. UNIQUE treats upper- and lower-case text as the same value. For a case-sensitive list you need a formula with EXACT, for example inside FILTER.

Does UNIQUE work in Excel 2019?

No. UNIQUE needs Microsoft 365, Excel 2021 or later, or Excel for the web. In older versions use Remove Duplicates on a copy of the data, a PivotTable or a formula with a first-occurrence flag.

Practise it in a lab

Related guides

Reading is step one. Doing is step two.

Every guide links to a lab where you build the same calculation in an online spreadsheet and get instant feedback.

Open the lab