ReferenceFunctionsLookup Functions
SORTBY
SORTBY: Sorts an array based on one or more aligned sort-by arrays.
Summary
SORTBY separates what is returned (array) from what determines ordering (by_array).
Remarks
- Requires at least one
by_arrayaligned to the row count ofarray. sort_orderdefaults to ascending when omitted.- Additional
by_array/sort_ordercriteria are processed left-to-right. - Shape mismatches or invalid criteria return
#VALUE!. - Returns a spilled sorted array.
Examples
Sort names by score
Grid
| Cell | Value | |
|---|---|---|
Formula
=
Result
Not evaluated yet.
Expected
[["Alice"],["Bob"],["Charlie"]]
Sort descending by key
Grid
| Cell | Value | |
|---|---|---|
Formula
=
Result
Not evaluated yet.
Expected
[["Q2"],["Q3"],["Q1"]]
Related functions
FAQ
How are multiple sort criteria applied?
SORTBY evaluates criteria left-to-right, using later by_array values only when earlier criteria compare equal.
Why do I get #VALUE! with SORTBY?
Each by_array must be one-dimensional and aligned to the primary array row count; mismatched shapes return #VALUE!.
Runtime metadata
Category
Lookup
Signature
SORTBY(arg1: Range (Range), arg2: Range (Range), arg3?…: Number)Arity
min 2, max variadic
Arguments
arg1by-refRange · Range
arg2by-refRange · Range
arg3optionaldefaultNumber · Scalar · coercion NumberLenientText
Caps
PURE
Source