Start free

FILTER, UNIQUE and SORT: an Excel interview question

Works in Excel 365, 2021 and later, and Excel for the web

Key takeaways

  • FILTER keeps the rows that pass a test, UNIQUE lists each value once, SORT puts them in order. Nest them, inside out.
  • One formula fills as many cells as it needs: it spills, and resizes when the data changes.
  • Leave the cells below a spilling formula empty, or it shows #SPILL!.
  • Give FILTER a third argument for when nothing matches, or it returns #CALC!.
  • To count the list, wrap it in ROWS, with IFERROR for a region with no orders: COUNTA would count the #CALC! as 1.
Jump straight to the practice sheet
On this page

Nest SORT, UNIQUE and FILTER, inside out: =SORT(UNIQUE(FILTER(A2:A9,B2:B9=F1))). FILTER keeps the customers whose region is the one in F1, UNIQUE lists each of them once, and SORT puts them A to Z. The result spills down as many cells as it needs and updates the moment an order or the region in F1 changes. Wrap it in ROWS to count the customers instead of listing them.

The question

“Here’s this quarter’s order list. On a summary sheet, list the customers who ordered in whichever region I type in a cell, each one once, alphabetically. It should update by itself when new orders come in.”

The older version of this question expects a pivot table or Remove Duplicates. If the company runs Microsoft 365, the interviewer usually wants to see whether you know there’s now a one-formula answer.

What they’re really testing

  • Whether you know dynamic arrays. One formula that returns a whole list, instead of a manual copy, a pivot table or a helper column.
  • The order of the steps. Filter first, then remove repeats, then sort.
  • Spill behaviour. What happens when the cells below aren’t empty, or when nothing matches.
  • Counting a list. A follow-up such as “and how many are there?” checks you can wrap the result.

The worked answer, one step at a time

The orders are in A1:C9 and the region to show in F1. Say each step out loud as you add it. First, FILTER keeps the names of the West orders, repeats and all:

E3=FILTER(A2:A9,B2:B9=F1)
RowABCDEF
1CustomerRegionAmountRegionWest
2Rowan LtdWest820
3Atlas CoEast450Rowan Ltd
4Mira FoodsWest1300Mira Foods
5Rowan LtdWest640Rowan Ltd
6Kite LabsNorth980Atlas Co
7Atlas CoWest300Mira Foods
8Mira FoodsWest210
9Orbit IncEast760

UNIQUE around it lists each customer once, in the order they first appear:

=UNIQUE(FILTER(A2:A9,B2:B9=F1)) → Rowan Ltd

SORT around that puts them A to Z. That’s the whole answer:

E3=SORT(UNIQUE(FILTER(A2:A9,B2:B9=F1)))
RowABCDEF
1CustomerRegionAmountRegionWest
2Rowan LtdWest820
3Atlas CoEast450Atlas Co
4Mira FoodsWest1300Mira Foods
5Rowan LtdWest640Rowan Ltd
6Kite LabsNorth980
7Atlas CoWest300
8Mira FoodsWest210
9Orbit IncEast760

Type another region in F1 and the list changes size to fit. To pick up new orders as well, turn the data into a table (Ctrl+T) and point the formula at its columns, such as Orders[Customer]: a table’s columns grow as rows are added.

The follow-up: how many customers?

Wrap the list in ROWS, or COUNTA, and you get a count instead of a list:

=ROWS(UNIQUE(FILTER(A2:A9,B2:B9=F1))) → 3

The West region has five orders from three customers. A COUNTIF on the region would say five, which answers a different question.

When nothing matches

With a region that has no orders, FILTER has nothing to return, and without a fallback it shows #CALC!. Its third argument is what to show instead:

=FILTER(A2:A9,B2:B9=F1,"No orders") → No orders

The count needs the same care. COUNTA counts an error as a value, so for a region with no orders it says 1 customer, with or without the fallback. Count with ROWS and catch the #CALC! with IFERROR, and an empty region shows 0:

=IFERROR(ROWS(UNIQUE(FILTER(A2:A9,B2:B9=F1))),0) → 0

The order of the steps matters

Remove the repeats first and then try to filter, and FILTER gets a list of names that no longer lines up with the regions beside it. The ranges are different sizes, so it returns #VALUE!:

Wrong=FILTER(UNIQUE(A2:A9),B2:B9=F1)#VALUE!
Right=SORT(UNIQUE(FILTER(A2:A9,B2:B9=F1)))Atlas Co

Filter while the names still sit next to their regions, then take UNIQUE of what’s left.

Common wrong answers, and why they fail

  1. Counting orders instead of customers. COUNTIF on the region counts every order, repeats included.
  2. UNIQUE before FILTER. The ranges no longer line up, and FILTER returns #VALUE!.
  3. Something in the way. A note or a value below the formula blocks the list, which shows #SPILL! until the cells are cleared.
  4. No fallback for an empty result. A region with no orders shows #CALC!.
  5. Copying the formula down. A spilling formula goes in one cell only. Copied down, each copy sits in the way of the list above it, so the formulas above show #SPILL!.

Practise it: count the different customers

A different order list and a count instead of a list. We check your count, then switch the region and change a customer’s name.

Your task: In E2, count how many different customers ordered in the region in E1.

Graded live
RowABCDE
1CustomerRegionRegionEast
2Lumen AGEastCustomers
3Bay TradersWest
4Lumen AGEast
5NorthwindEast
6Peak SupplyNorth
7Bay TradersEast
8NorthwindEast
9Cedar LtdWest
10Lumen AGEast

Write the formula in the bar above, then press Check or Enter.

Hint

FILTER(A2:A10,B2:B10=E1) keeps the region's names, UNIQUE lists each once, and ROWS (or COUNTA) counts them.

Solution

=ROWS(UNIQUE(FILTER(A2:A10,B2:B10=E1))) Any formula that returns the same result passes.

How to answer it in the interview

“FILTER to the region in F1, UNIQUE so each customer shows once, SORT for A to Z, all in one cell, and it spills. I’d give FILTER a fallback for a region with no orders, and keep the cells below it clear.” If they ask for an older version, say pivot table or Remove Duplicates, and that neither updates by itself. More questions like this one: Excel interview questions.

Practise this in a lessonHow many different customers?A full exercise in the app's live grid, graded on what your formula calculates.Open the lesson

FAQ

Do FILTER, UNIQUE and SORT work in Excel 2019?

No. They need Excel 365, Excel 2021 or later, or Excel for the web. Older versions show #NAME?. There, a pivot table or Remove Duplicates gets you the same list, but it won't update by itself.

What's the difference between UNIQUE and Remove Duplicates?

Remove Duplicates deletes rows from your data, once. UNIQUE leaves the data alone and returns a list that updates whenever the data changes.

How do I filter on more than one condition?

Multiply the tests for AND, add them for OR: =FILTER(A2:A9,(B2:B9="West")*(C2:C9>500)) keeps West orders over 500.

Will an interviewer accept a pivot table instead?

Ask what the list is for. If it must update by itself, a pivot table needs refreshing and Remove Duplicates is a one-off, so the formula is the answer they want. Offering both, and saying why you'd pick one, shows judgement.

Summarize this guide withChatGPTPerplexityClaude

Keep going

Guides that build on this one.

All guides
Interview prepPractice sheet

SUMIFS interview question: summarise sales by region

Turn a raw sales list into a summary by region and product, without a pivot table. The formula interviewers expect, the $ signs that make it copy, and a sheet that grades yours.

4 min read · Updated
Modern Excel

XLOOKUP vs VLOOKUP: which should you use?

XLOOKUP does everything VLOOKUP does with fewer ways to go wrong. Here's the same lookup written both ways, the five differences that matter, and when VLOOKUP is still the right call.

2 min read · Updated

Reading is step one. Writing the formula is the skill.

Practise in a live grid that grades what your formula calculates, with a specific hint when it's wrong.

Runs in your browser · Graded on your result · No install