Arte SheetsLearn. Try. Understand.

Dynamic arrays

SORTBY function: sort by multiple columns or by a column excluded from output

Rank data across two or more tie-breaker columns—and return only the columns you want to display—using SORTBY.

Why SORTBY goes further than SORT

Whereas SORT requires the sort key to be a column number inside the returned range, SORTBY(array, by_array1, [sort_order1], [by_array2], [sort_order2], ...) accepts separate range references.

That unlocks two everyday workflows: returning just Candidate names (A2:A5) sorted by hidden/external columns, and chaining multi-level tie-breakers such as Priority Tier ascending (1) followed by Score descending (-1).

Candidate (A)Tier (B)Score (C)
Liam292
Maya185
Noah194
Zoe288

Two-level sort: Tier ascending (1), then Score descending (-1)

Tier 1 candidates come first (Noah 94 beats Maya 85), followed by Tier 2 candidates (Liam 92 beats Zoe 88), yielding Noah, Maya, Liam, Zoe.

=TEXTJOIN(", ", TRUE, SORTBY(A2:A5, B2:B5, 1, C2:C5, -1))

Mismatched range lengths return #VALUE!

Every by_array must have the same height (or width for horizontal sorts) as the returned array; passing B2:B4 against A2:A5 returns #VALUE!.

=SORTBY(A2:A5, B2:B4, 1)

Try the example

Use the original values or change them to test your understanding.

Further reading