The SORTBY function

Sorts a range by the values in another range, which need not be part of the result. Add more by-range and order pairs to break ties.

Syntax

SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], ...)
array
The range to sort and return.
by_array1
The range to sort by, one value per row of array.
sort_order1 (optional)
1 or left out for smallest to largest, -1 for largest to smallest.
by_array2, sort_order2 (optional)
More ranges and orders, used when the earlier ones tie.

Examples

E1=SORTBY(A2:A5,C2:C5,-1)
ABCDE
1NameTeamSalesBen
2MayaEast320Maya
3BenWest450Ava
4ZoeEast180Zoe
5AvaWest275

In plain words: Sort the names in A2:A5 by the sales in C2:C5, largest first.

E1=SORTBY(A2:C5,B2:B5,1,C2:C5,-1)
ABCDEFG
1NameTeamSalesMayaEast320
2MayaEast320ZoeEast180
3BenWest450BenWest450
4ZoeEast180AvaWest275
5AvaWest275

Questions

What is the difference between SORT and SORTBY?

SORT sorts by a column number inside the range. SORTBY sorts by a separate range, so the column you sort by does not have to be in the result, and several sort levels are easy to add.

How do I sort by two columns?

Give SORTBY two pairs, as in =SORTBY(A2:C5,B2:B5,1,C2:C5,-1). It sorts by team first and, inside each team, by sales from highest to lowest.

Related functions