ReferenceFunctionsLookup Functions
SORT
Sorts an array by a selected row or column and returns a spilled result.
Summary
SORT can order rows (default) or columns.
Remarks
- Defaults:
sort_index=1,sort_order=1(ascending),by_col=FALSE. sort_indexis 1-based in the active sort axis.sort_order < 0sorts descending; otherwise ascending.- Invalid sort indexes return
#VALUE!. - Empty input returns an empty spill.
Examples
Sort rows by second column
Grid
| Cell | Value | |
|---|---|---|
Formula
=
Result
Not evaluated yet.
Expected
[["A",10],["B",20],["C",30]]
Sort columns by first row descending
Grid
| Cell | Value | |
|---|---|---|
Formula
=
Result
Not evaluated yet.
Expected
[[3,2,1],["C","B","A"]]
Related functions
FAQ
What changes when by_col is TRUE?
SORT reorders columns instead of rows, and sort_index is interpreted as a row index used as the sort key.
What causes #VALUE! in SORT?
If sort_index is outside the active axis (row or column axis based on by_col), SORT returns #VALUE!.
Runtime metadata
Category
Lookup
Signature
SORT(arg1: Range (Range), arg2?: Number, arg3?: Number, arg4?…: Logical)Arity
min 1, max variadic
Arguments
arg1by-refRange · Range
arg2optionaldefaultNumber · Scalar · coercion NumberLenientText
arg3optionaldefaultNumber · Scalar · coercion NumberLenientText
arg4optionaldefaultLogical · Scalar · coercion Logical
Caps
PURE
Source