1. Home
  2. Functions
  3. Array
  4. SORTBY

SORTBY function

Sorts a range or array by the values of other ranges or arrays.

Syntax

=SORTBY(array, by_array1, [sort_order1], ...)

Arguments

ArgumentRequiredDescription
arrayRequiredThe range or array to sort
by_array1RequiredA row or column to sort by
sort_order1Optional1 ascending (default), -1 descending

How to use SORTBY

When SORTBY returns more than one value, the result spills into the cells below and to the right. Keep those cells empty, or you get #SPILL!.

SORTBY takes 2 required arguments and 1 optional argument, and accepts more values in the same pattern. Type =SORTBY( in a cell and SheetsBat shows the arguments as you go. Optional arguments are shown in square brackets; leave them out to use their default.

Examples

Each result below was calculated by the SheetsBat formula engine.

=SORTBY({"a";"b";"c"}, {3;1;2})Result 3 by 1 array
Spilled result
A
1b
2c
3a
=SORTBY({"a";"b";"c"}, {3;1;2}, -1)Result 3 by 1 array
Spilled result
A
1a
2c
3b

Every formula, right in your browser

SheetsBat calculates 536 functions, with charts, pivot tables and live collaboration. Free to start.