Syntax
=SORTBY(array, by_array1, [sort_order1], ...)Arguments
| Argument | Required | Description |
|---|---|---|
array | Required | The range or array to sort |
by_array1 | Required | A row or column to sort by |
sort_order1 | Optional | 1 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 Spilled result
| A | |
|---|---|
| 1 | b |
| 2 | c |
| 3 | a |
=SORTBY({"a";"b";"c"}, {3;1;2}, -1)Result Spilled result
| A | |
|---|---|
| 1 | a |
| 2 | c |
| 3 | b |
Related array functions
- REDUCEReduces an array to one value by applying a LAMBDA to an accumulator and each value.
- SCANApplies a LAMBDA to each value with a running accumulator and returns every intermediate result.
- SEQUENCEReturns a list of sequential numbers in an array of the given size.
- SORTSorts the rows or columns of a range or array.
- SORTNReturns the first n rows of a range after sorting, with options for ties.
- TAKEReturns a number of rows or columns from the start (positive) or end (negative) of an array.
- TOCOLReturns the values of an array as a single column.
- TOROWReturns the values of an array as a single row.
- TRIMRANGERemoves empty rows and columns from the edges of a range.