Sorting with SORTBY: practice exercises
SORTBY, biggest first, two sort columns, sorting by a column you don't show. 6 exercises on real-looking data, each marked the moment you press Check. The first exercise is below to try now; the full lesson is part of Pro.
In J2, use SORTBY to list the names in order of sales, smallest first. Only the names should show.
| A | B | C | D | E | F | G | H | I | J | |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Name | Team | Sales (£) | Started | Lowest sales first | |||||
| 2 | Hamza | Marketing | £3,770.00 | 08/07/2023 | ||||||
| 3 | Grace | Marketing | £3,850.00 | 03/02/2016 | ||||||
| 4 | Tom | IT | £3,000.00 | 17/08/2022 | ||||||
| 5 | Lucy | Sales | £2,440.00 | 30/05/2021 | ||||||
| 6 | Jordan | Marketing | £1,650.00 | 12/06/2024 | ||||||
| 7 | Owen | Sales | £3,360.00 | 23/02/2024 | ||||||
| 8 | Chen | IT | £1,740.00 | 10/03/2020 | ||||||
| 9 | Sam | Marketing | £570.00 | 08/09/2022 | ||||||
| 10 | Zoe | Sales | £3,630.00 | 29/04/2019 | ||||||
| 11 | Rachel | Sales | £2,630.00 | 31/01/2016 | ||||||
| 12 | Will | Sales | £840.00 | 29/04/2016 | ||||||
| 13 | Hannah | IT | £3,320.00 | 01/04/2017 | ||||||
| 14 | Ivan | Sales | £710.00 | 19/05/2024 | ||||||
| 15 | Marek | IT | £2,940.00 | 22/01/2018 | ||||||
| 16 | Ella | IT | £210.00 | 19/01/2024 |
How it works
SORTBY(what to show, sort by this) lists cells in the order of another column. Unlike the Sort button, the original data stays as it is, and the sorted list updates by itself when the data changes. Like FILTER and UNIQUE, the answer spills down from the cell you type it in.
Add -1 after a sort column for biggest first (or newest, or Z to A). Add a second column and order to break ties, and so on.
=SORTBY(A2:A6,C2:C6) =SORTBY(A2:C6,C2:C6,-1) =SORTBY(A2:C6,B2:B6,1,C2:C6,-1)
SORTBY, step by step
=SORTBY(A2:A6,C2:C6) means: show A2:A6, in the order of C2:C6, smallest first. The column you sort by doesn't have to be one you show.
- Biggest first: put -1 after the sort column,
=SORTBY(A2:A6,C2:C6,-1). 1 (or nothing) means smallest first, A to Z, or oldest date first. - Two levels: add another column and order,
=SORTBY(A2:C6,B2:B6,1,C2:C6,-1): by team A to Z, then by sales biggest first within each team.
The ranges must be the same height (A2:A6 and C2:C6), or you get #VALUE!. SORTBY is in Excel 2021 and later, Excel 365, Excel for the web and Google Sheets.
Worked example: one column
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Name | Team | Sales (£) | |||
| 2 | Amira | Sales | £520.00 | |||
| 3 | Ben | Finance | £300.00 | |||
| 4 | Cara | Sales | £380.00 | |||
| 5 | Dev | Finance | £450.00 | |||
| 6 | Ewa | Sales | £400.00 |
=SORTBY(A2:A6,C2:C6)in E2. The names in order of sales, smallest first: Ben (£300), Cara (£380), Ewa (£400), Dev (£450), Amira (£520). The sales themselves aren't shown.=SORTBY(A2:A6,C2:C6,-1)in E2. With -1, biggest first: Amira, Dev, Ewa, Cara, Ben.
Worked example: two levels
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Name | Team | Sales (£) | |||
| 2 | Amira | Sales | £520.00 | |||
| 3 | Ben | Finance | £300.00 | |||
| 4 | Cara | Sales | £380.00 | |||
| 5 | Dev | Finance | £450.00 | |||
| 6 | Ewa | Sales | £400.00 |
=SORTBY(A2:C6,B2:B6,1,C2:C6,-1)in E2. Team first, A to Z: Finance before Sales. Within Finance, Dev (£450) comes before Ben (£300); within Sales, Amira, Ewa, then Cara. The answer spills across three columns.
SORT or SORTBY?
SORT(A2:C6,3,-1) sorts by the 3rd column of what it shows. It's shorter when the column you sort by is one you show.
SORTBY names the sort column as a range, so it can sort by a column you don't show, and it keeps working if columns are added or moved. See the guide to SORT and SORTBY for more.
What you'll practise
- In J2, use SORTBY to list the names in order of sales, smallest first. Only the names should show.
- In J2, use SORTBY to show the whole table (all four columns) with the biggest sales first.
- In J2, show the whole table sorted by team, A to Z, and within each team by sales, biggest first.
- In J2, use SORTBY to list just the names, with the person who started most recently first. The start dates are sorted on but not shown.
- In J2, write one formula that lists each person's name and team (columns A and B only). Order it by team from A to Z and, within each team, with the earliest start date first. It should update by itself when the data changes.
- In J2, write one formula that lists only the names, ordered from the highest sales to the lowest. It should update by itself when the sales change.
Guides with worked examples: SORT and SORTBY: sorted lists that keep up · DROP, TAKE and CHOOSEROWS: picking rows from a table · VSTACK and HSTACK: joining lists in Excel