Formualizer Docs
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_array aligned to the row count of array.
  • sort_order defaults to ascending when omitted.
  • Additional by_array/sort_order criteria are processed left-to-right.
  • Shape mismatches or invalid criteria return #VALUE!.
  • Returns a spilled sorted array.

Examples

Sort names by score
Grid
CellValue
Formula
=
Result
Not evaluated yet.
Expected
[["Alice"],["Bob"],["Charlie"]]
Sort descending by key
Grid
CellValue
Formula
=
Result
Not evaluated yet.
Expected
[["Q2"],["Q3"],["Q1"]]

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

Range · Range

arg2by-ref

Range · Range

arg3optionaldefault

Number · Scalar · coercion NumberLenientText

Caps

PURE

Source

On this page