XLOOKUP Multiple Criteria — With Examples (Boolean Logic, Concatenation, OR)
Learn XLOOKUP with multiple criteria in Excel: Boolean logic, concatenation, helper columns and OR logic, with worked examples.
Read Guide →Your Region column has ten rows and four regions — East, West, North, South — with East written four times and West three. You need the clean list: each region once, in the order it first appears, and you need it to update itself when the data changes. That is the UNIQUE function: =UNIQUE(B2:B11). You type it once, in one cell, and the list spills down below it. This guide gives you that formula first, then runs it on the ten-order sales table, so you can check each answer yourself — the distinct list, the values that appear exactly once, the count, the blank case, the sorted list, and the two-column case — plus the #SPILL! and #NAME? fixes, and the older-Excel method.
Quick takeaway: one formula, typed once, spills the whole list.
=UNIQUE(B2:B11) — each distinct value once, in the order it first appears.=UNIQUE(B2:B11,,TRUE) — only the values that appear exactly once.=COUNTA(UNIQUE(B2:B11)) — COUNTA, not COUNT, for text.
=UNIQUE(array, [by_col], [exactly_once])
| Argument | Required | What it does |
|---|---|---|
| array | Yes | The range or array you want the distinct values from |
| by_col | No | FALSE (the default) compares rows; TRUE compares columns, for data that runs across a row |
| exactly_once | No | FALSE (the default) returns one of every distinct value; TRUE returns only the values that appear exactly once |
The two optional arguments are positional. To set exactly_once without by_col, leave an empty slot with an extra comma: =UNIQUE(B2:B11,,TRUE).
Every example below uses the same ten-order sales table from the COUNTIF, SUMIF and Highlight Row articles — Rep, Region, Sales, Order Date, Status, Notes — in rows 2 to 11. Every result was counted against it.
| Formula | Result (spills down) | Count |
|---|---|---|
=UNIQUE(B2:B11) — Regions | East, West, North, South | 4 |
=UNIQUE(A2:A11) — Reps | Alex, Priya, Jordan, Sam, Taylor | 5 |
=UNIQUE(E2:E11) — Status | Paid, Pending | 2 |
=SORT(UNIQUE(B2:B11)) — Regions, A to Z | East, North, South, West | 4 |
Read the rows. The Regions list has 4 values, not 5 — and that is the case trap. Row 4 has the region written “east” in lowercase, and UNIQUE is not case-sensitive: “east” and “East” count as the same value, so only the first one, “East”, appears in the list. Extra spaces are different, though — “East ” with a trailing space is not “East” — so clean the data with TRIM first. And the list is in the order each value first appears, not A to Z — wrap it in SORT for the alphabetical list.
“Unique” means two different things, and UNIQUE does both. By default it returns the distinct values — every region once, however many orders it had. Set exactly_once to TRUE and it returns only the values that appear exactly once:
| Formula | Result | Count |
|---|---|---|
=UNIQUE(B2:B11,,TRUE) — Regions appearing once | South | 1 |
=UNIQUE(A2:A11,,TRUE) — Reps appearing once | Taylor | 1 |
South appears once in the ten orders, so it is the only region in the exactly-once list. Taylor is the only rep with one order — Alex has 3, Priya 2, Jordan 2 and Sam 2. Exactly once is strict: any duplicate count breaks the value. That is what makes it useful for spotting one-off entries — a customer who ordered a single time, or an invoice ID that appears once when it should appear twice.
| Formula | Result | Why |
|---|---|---|
=COUNTA(UNIQUE(B2:B11)) — distinct regions | 4 | COUNTA counts the items in the spilled list |
=COUNTA(UNIQUE(A2:A11)) — distinct reps | 5 | The same, on the Rep column |
=COUNT(UNIQUE(B2:B11)) | 0 | COUNT only counts numbers, so it returns 0 for a list of names |
Use COUNTA, not COUNT: COUNT only counts numbers, so it returns 0 for a list of names. If the list is already on the sheet, you can count it with a spill reference — the first cell of the spill followed by #. With the regions spilled from H2, =COUNTA(H2#) returns 4. Unlike a fixed range such as H2:H5, H2# grows and shrinks with the list, so the count stays right when a new region appears. To count distinct values that meet a condition, filter first: =COUNTA(UNIQUE(FILTER(A2:A11, B2:B11="East"))) returns 3 — the number of different East reps: Alex, Jordan and Priya.
The Notes column has 4 blank cells and 6 filled ones — Rush 3 times, Gift wrap, Call first and Delivery once each:
| Formula | Result | Count |
|---|---|---|
=UNIQUE(F2:F11) — Notes, blanks included | Rush, 0, Gift wrap, Call first, Delivery | 5 |
=UNIQUE(FILTER(F2:F11, F2:F11<>"")) — Notes, blanks excluded | Rush, Gift wrap, Call first, Delivery | 4 |
The blank shows as a 0 at the bottom of the list — UNIQUE returns 0 for the empty cells in the range. Filter the blanks out first with =UNIQUE(FILTER(F2:F11, F2:F11<>"")) and the 0 is gone. The same FILTER pattern is the one to use when the range runs past the last entry.
Give UNIQUE more than one column and it compares whole rows — a row counts as a duplicate only when all its values match:
| Formula | Result | Count |
|---|---|---|
=UNIQUE(B2:E11) — Region + Status pairs | East/Paid, West/Pending, North/Paid, East/Pending, South/Paid | 5 |
Ten orders, five distinct Region-and-Status pairs. Alex’s East/Paid order and Taylor’s East/Paid order are the same pair, so they appear once. And a rep who bought in two regions would appear twice, once per region — Priya appears as West/Pending and East/Pending, two different pairs.
When the values run across a row instead of down a column, set by_col to TRUE:
=UNIQUE(B2:G2, TRUE)
On the row East, West, East, North, West, South that returns East, West, North, South — spilling to the right instead of down. With several columns and by_col left out, UNIQUE compares rows; with by_col TRUE it compares columns. You will rarely need it — most lists run down a column — but when the data runs across, it is the only argument that changes.
UNIQUE works in Microsoft 365, Excel 2024, and Excel 2021 (Windows and Mac), and in Excel for the web. Excel 2019 and earlier do not have it and show a #NAME? error. Two ways round it:
=SUMPRODUCT(1/COUNTIF(B2:B11, B2:B11)) returns 4 — the same count as COUNTA(UNIQUE(…)). It works because each East row contributes 1/4, each West row 1/3, each North row 1/2 and the South row 1/1, and 1/4 + 1/4 + 1/4 + 1/4 + 1/3 + 1/3 + 1/3 + 1/2 + 1/2 + 1 = 4.| Mistake | What happens | Fix |
|---|---|---|
| You used COUNT instead of COUNTA | 0 — COUNT only counts numbers | Use =COUNTA(UNIQUE(...)) |
| You forgot the spill space | #SPILL! — a cell in the way is not empty | Clear the cells below the formula |
| You used UNIQUE in old Excel | #NAME? — the function does not exist there | Use Remove Duplicates, or the SUMPRODUCT count |
| You forgot the empty slot | =UNIQUE(B2:B11, TRUE) sets by_col, not exactly_once | Use two commas: =UNIQUE(B2:B11,,TRUE) |
| You expected A-to-Z order | UNIQUE keeps the order of first appearance | Wrap it in SORT: =SORT(UNIQUE(...)) |
| You left blanks in the range | A 0 appears at the bottom of the list | Filter them out: =UNIQUE(FILTER(range, range<>"")) |
| You counted on the spill with a fixed range | The count goes wrong when the list grows | Use the spill reference: =COUNTA(H2#) |
How do I get unique values from a column in Excel? =UNIQUE(B2:B11) — type it once in one cell, and the distinct values spill down below it, in the order they first appear.
What is the difference between unique and exactly once? By default UNIQUE returns one of every distinct value. With exactly_once TRUE — =UNIQUE(B2:B11,,TRUE) — it returns only the values that appear a single time.
How do I count unique values in a column? =COUNTA(UNIQUE(B2:B11)) — COUNTA, not COUNT, because COUNT only counts numbers. On the Regions column that returns 4.
Why does my unique list show a 0 at the bottom? Your range contains empty cells, which UNIQUE returns as 0. Filter them out: =UNIQUE(FILTER(B2:B11, B2:B11<>"")).
Why do I get #SPILL!? The cells where the result needs to go are not empty. Clear them and the list appears.
Is UNIQUE case-sensitive? No. Values that differ only in upper and lower case are treated as the same — “east” and “East” count as one value. Extra spaces are different, so clean the data with TRIM first.
What if my Excel does not have UNIQUE? It needs Microsoft 365, Excel 2024 or Excel 2021. In older Excel, use Data > Remove Duplicates for a one-off list, or =SUMPRODUCT(1/COUNTIF(range, range)) to count.
That is the UNIQUE function in Excel: =UNIQUE(B2:B11) types once and spills the whole distinct list — East, West, North, South from ten orders — in the order each value first appears, and the list updates itself when the data changes. On the table in this guide, that one formula answers every question: the distinct regions are 4, the distinct reps are 5, the values appearing exactly once are South and Taylor, the count is =COUNTA(UNIQUE(...)) — 4 for regions, 5 for reps — and the blanks are a 0 until you filter them out. Remember the two things that catch everyone once: UNIQUE is not case-sensitive, so “east” and “East” are one value, while a trailing space makes a different one — and the spill cells must be empty, or you get #SPILL!. In older Excel there is no UNIQUE: Remove Duplicates for a one-off list, or =SUMPRODUCT(1/COUNTIF(range, range)) for the count. From here, the next functions worth learning are the ones this one sits next to — the FILTER function for the filter inside the blank-free list, the XLOOKUP function for looking up the values once you have them — and the full learning order for the whole site is on the Excel Formulas hub and the Lookup topic page.
Learn XLOOKUP with multiple criteria in Excel: Boolean logic, concatenation, helper columns and OR logic, with worked examples.
Read Guide →Learn the MATCH function in Excel: exact and approximate matches, wildcards, INDEX MATCH lookups, two-way lookups and XMATCH.
Read Guide →Learn the INDIRECT function in Excel: turn text into a live cell reference, pull from a sheet named in a cell, and...
Read Guide →