Excel SORTBY
SORTBY returns a list in the order set by another column, without moving your original data.
A sales manager wants a leaderboard that shows only names but is ordered by revenue. Sorting the source would disturb a table others rely on. SORTBY produces a separate ranking that reorders itself when new figures are entered.
Practice it nowHow to write it
=SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], ...)- array
- What to return.
- by_array1
- The column that decides the order.
- sort_order1
- 1 is ascending and -1 is descending.
- by_array2, sort_order2
- Optional tie-breaker.
Watch it work
F2fx
ABCDEFG
1RepRegionQ3 salesDeals
2RosaEast4800012
3SamWest610009
4TaraEast3900015
5UmarNorth7200011
6VeraWest5500014
7
1
Examples
Best seller first
=SORTBY(A2:A6,C2:C6,-1)UmarNames are returned, ordered by sales from high to low.
Most deals first
=SORTBY(A2:A6,D2:D6,-1)TaraChange the by-column and you have a different leaderboard.
By region, then highest sales
=SORTBY(A2:A6,B2:B6,1,C2:C6,-1)RosaEast comes first alphabetically and Rosa outsold Tara.
Your turn
List the reps from lowest Q3 sales to highest. Type your formula in F2.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Rep | Region | Q3 sales | Deals | ||
| 2 | Rosa | East | 48000 | 12 | ||
| 3 | Sam | West | 61000 | 9 | ||
| 4 | Tara | East | 39000 | 15 | ||
| 5 | Umar | North | 72000 | 11 | ||
| 6 | Vera | West | 55000 | 14 | ||
| 7 |
Common mistakes
The by-column has a different height.
Excel returns #VALUE!. All ranges must match in size.
Blocked spill area.
Clear the cells below the formula to fix #SPILL!.
Good to know
- The by-column need not appear in the output, unlike with SORT.
- Combine with TAKE to show only the top three.
- SORTBY or SORT? SORT orders by a column number inside the returned range. SORTBY orders by any separate range.
Excelio