SORTBY
Returns a new array of objects sorted by a specified property.
Syntax
SORTBY(array, property, [direction])
Arguments
array: The array of objects to sort.property: The property name to sort by.direction(optional):"asc"for ascending (default) or"desc"for descending.
Example
SORTBY([{d: 3}, {d: 1}, {d: 2}], "d") → Returns [{d: 1}, {d: 2}, {d: 3}].
SORTBY([{d: 3}, {d: 1}, {d: 2}], "d", "desc") → Returns [{d: 3}, {d: 2}, {d: 1}].
SORTBY is commonly used to put a packed-object array (for example, payment entries pulled from Financial Ledger) into chronological order before walking it with THRESHOLDBYSUM:
SORTBY(FILTER({{Packed Ledgers}}, {type: "Payment"}), "date", "asc")
Usage Notes:
- SORTBY does not mutate the input array, it returns a new sorted array.
- Non-array input returns an empty array
[]. - Any
directionvalue other than"desc"(case-insensitive) is treated as ascending. - If an object is missing the sort property, it sorts as
undefinedand is placed at the end of an ascending sort (and the start of a descending one).