Formualizer Docs
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_index is 1-based in the active sort axis.
  • sort_order < 0 sorts descending; otherwise ascending.
  • Invalid sort indexes return #VALUE!.
  • Empty input returns an empty spill.

Examples

Sort rows by second column
Grid
CellValue
Formula
=
Result
Not evaluated yet.
Expected
[["A",10],["B",20],["C",30]]
Sort columns by first row descending
Grid
CellValue
Formula
=
Result
Not evaluated yet.
Expected
[[3,2,1],["C","B","A"]]

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-ref

Range · Range

arg2optionaldefault

Number · Scalar · coercion NumberLenientText

arg3optionaldefault

Number · Scalar · coercion NumberLenientText

arg4optionaldefault

Logical · Scalar · coercion Logical

Caps

PURE

Source

On this page