Formualizer Docs

SORT

Sorts an array by a selected row or column and returns a spilled result.

SORT can order rows (default) or columns.

The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.

Syntax

=SORT(array, [sort_index], [sort_order], [by_col])

Arguments

ArgumentTypeRequiredDefault
arrayrange (range)Required—
sort_indexnumberOptional1
sort_ordernumberOptional1
by_collogicalOptionalfalse

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.
  • Empty input returns an empty spill.

Error cases

  • Invalid sort indexes return #VALUE!.

Examples

Sort a column in ascending order.

Formula =SORT({30;10;20})

Expected result {10; 20; 30}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Sort a two-column table descending by its first column.

Formula =SORT({30,"Cy";10,"Ana";20,"Bo"},1,-1)

Expected result {30, "Cy"; 20, "Bo"; 10, "Ana"}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Sorting a one-element array leaves the element in place.

Formula =SORT({42})

Expected result 42

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

A sort index outside the available columns cannot select a key.

Formula =SORT({30;10;20},2)

Expected result #VALUE!

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Sort rows by second column

Formula =SORT(A1:B3,2,1,FALSE)

Input cells
AB
1"C"30
2"A"10
3"B"20

Expected result {"A", 10; "B", 20; "C", 30}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Sort columns by first row descending

Formula =SORT(A1:C2,1,-1,TRUE)

Input cells
ABC
1132
2"A""C""B"

Expected result {3, 2, 1; "C", "B", "A"}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

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!.

Implementation

Engine source

On this page