SheetRocks
Documentation/Formulas/SORTBY

SORTBY

Sorts a range or array based on values in one or more corresponding ranges or arrays.

Syntax

SORTBY(array, by_array1, [sort_order1], [by_array_n], [sort_order_n])

Arguments

Argument Description Required
array The array or range to sort. Required
by_array1 The first array or range to sort by. Required
sort_order1 The sort order for the first by_array: 1 for ascending (default), -1 for descending. Optional
by_array_n Additional arrays or ranges to sort by. Optional
sort_order_n Sort orders for additional by_arrays. Optional

Examples

Sort names by age

=SORTBY(A1:A3, B1:B3)
Result ⇒ Array: [["Bob"], ["Alice"], ["Charlie"]]
A B
1 Alice 30
2 Bob 25
3 Charlie 35

Sort names by age descending

=SORTBY(A1:A3, B1:B3, -1)
Result ⇒ Array: [["Charlie"], ["Alice"], ["Bob"]]
A B
1 Alice 30
2 Bob 25
3 Charlie 35

Sort by city then age

=SORTBY(A1:C3, C1:C3, 1, B1:B3, 1)
Result ⇒ Array: [["Bob",25,"LA"], ["Alice",30,"NY"], ["Charlie",35,"NY"]]
A B C
1 Alice 30 NY
2 Bob 25 LA
3 Charlie 35 NY

Related Functions

Other Data functions:


← Back to Formula Reference