ExcelyourTraining

Home › Blog

Excel UNIQUE function, plus SORT and FILTER: turn messy data into a clean list

You have a sales list with the same region typed over and over. Your manager wants a tidy list of regions, sorted A to Z, and then every sale for Gauteng on its own. Doing that by hand means copying, deleting and hoping you didn't miss a row.

This guide shows you how to do it with three formulas. By the end you'll be able to use the Excel UNIQUE function to list each value once, wrap it in SORT to put it in order, and use FILTER to pull out every row that matches a condition. All three update by themselves when the data changes.

The example: a small sales team

Say Thandi manages sales reps across a few provinces. Her data sits in columns A to C:

A B C
1 Rep Region Sales
2 Thandi Gauteng R12 400
3 Pieter Western Cape R8 750
4 Aisha KwaZulu-Natal R15 200
5 Sipho Gauteng R6 300
6 Lerato Free State R9 900
7 Johan Western Cape R11 050
8 Naledi Gauteng R7 480
9 Ravi KwaZulu-Natal R4 600

Eight rows, four regions. The real list might have eight hundred rows, but the formulas are the same.

Step 1: list each region once with the Excel UNIQUE function

Click an empty cell, say F2, and type:

=UNIQUE(B2:B9)

Press Enter. Excel fills F2 to F5 with:

F
2 Gauteng
3 Western Cape
4 KwaZulu-Natal
5 Free State

You typed one formula, but the answer runs into four cells. That's called spilling. Click any cell in the result and you'll see a blue border around the whole spill range. Only F2 holds the formula. The cells below show its results.

UNIQUE keeps the order in which each value first appears. Gauteng is first because it's the first region in the data.

If you want a list of values that appear only once, UNIQUE has an optional third argument for that:

=UNIQUE(B2:B9,,TRUE)

Here that returns only Free State, because every other region appears at least twice.

UNIQUE or Remove Duplicates?

Many people know the Remove Duplicates button on the Data tab. It works, but it deletes rows from your data, and the result doesn't change when the data does. Add a new sale from Limpopo tomorrow and you have to do it all again.

UNIQUE leaves your original data alone and builds the list somewhere else. Add a row inside the range and the list updates. If you've been searching for an "Excel remove duplicates formula", this is it.

Step 2: sort the list A to Z

Wrap SORT around UNIQUE:

=SORT(UNIQUE(B2:B9))

Now the result reads:

G
2 Free State
3 Gauteng
4 KwaZulu-Natal
5 Western Cape

Excel works from the inside out. UNIQUE builds the list first, then SORT puts it in order. This sort unique Excel formula is probably the most useful pairing in modern Excel, and you'll use it for dropdown lists, report headings and summary tables.

SORT sorts ascending (A to Z, smallest to largest) by default. To reverse it, give it a sort order of -1:

=SORT(UNIQUE(B2:B9),,-1)

The empty middle argument tells Excel which column to sort by. With a single column, you can leave it out.

Step 3: pull out every matching row with the Excel FILTER function

Now for the Gauteng sales. Click I2 and type:

=FILTER(A2:C9,B2:B9="Gauteng")

FILTER needs two things: the data you want back (A2:C9) and a test for each row (is the region Gauteng?). It returns every row where the test is true:

I J K
2 Thandi Gauteng R12 400
3 Sipho Gauteng R6 300
4 Naledi Gauteng R7 480

This is where FILTER beats VLOOKUP. VLOOKUP stops at the first match and gives you Thandi only. FILTER gives you all three.

Show a message when nothing matches

Try the same formula with "Limpopo". There are no Limpopo sales, so Excel shows a #CALC! error. FILTER has an optional third argument for exactly this:

=FILTER(A2:C9,B2:B9="Limpopo","No sales")

Now the cell says "No sales" instead of an error. Get into the habit of adding it. Your report looks finished, and whoever reads it knows the empty result is real, not a broken formula.

FILTER with more than one condition

To filter on two things at once, put each test in brackets and join them.

Both conditions (AND): multiply them with *. Gauteng sales over R7 000:

=FILTER(A2:C9,(B2:B9="Gauteng")*(C2:C9>7000),"No sales")

That returns Thandi (R12 400) and Naledi (R7 480). Sipho's R6 300 is too low.

Either condition (OR): add them with +. Gauteng or Free State:

=FILTER(A2:C9,(B2:B9="Gauteng")+(B2:B9="Free State"),"No sales")

That returns Thandi, Sipho, Lerato and Naledi.

It's easy to mix these up, so check the row count against what you expect.

Sort the filtered rows

You can wrap SORT around FILTER too. To list Gauteng sales from biggest to smallest, sort by the third column, descending:

=SORT(FILTER(A2:C9,B2:B9="Gauteng"),3,-1)

The result: Thandi R12 400, Naledi R7 480, Sipho R6 300.

Make it interactive

Type a region into a cell, say M1, and point FILTER at that cell instead of typing the region into the formula:

=FILTER(A2:C9,B2:B9=M1,"No sales")

Change M1 from Gauteng to Western Cape and the results change straight away. Add a dropdown to M1 (Data > Data Validation > List) and you have a simple report anyone can use.

Two things to watch

Leave room for the spill. If any cell where the results need to go already has something in it, you get a #SPILL! error instead. Clear the cells below and to the right of your formula and it will spill again.

Check your Excel version. UNIQUE, SORT and FILTER are dynamic array functions. They work in Microsoft 365, Excel 2021, Excel 2024 and Excel for the web. Excel 2019 and older don't have them, and typing the formula there gives you a #NAME? error. If that's you, Excel for the web is free with a Microsoft account and has all three functions.

Try it yourself

Reading about spilling is one thing. Seeing a list fill itself in is another. Practise both steps in a real spreadsheet in your browser:

Each lesson takes a few minutes and is graded the moment you press Enter. It's free, with no sign-up and nothing to install.

ExcelyourTraining isn't affiliated with Microsoft. Excel is a trademark of Microsoft Corporation.