SORTBY

sorts a range or array by values in a corresponding range · from excel · excel: verified match · no sheets equivalent

signature

SORTBY(array, by_array1, [sort_order1], [by_array2…], [sort_order2…])

returns: array

argumentrequired
array required
by_array1 required
sort_order1 optional · defaults to 1
by_array2… optional
sort_order2… optional

examples

formula and result, taken from the engine's own test suite — every result below is asserted in CI, not written by hand.

AB
1 102
2 204
3 306
4 408
5 5010
fx =SORTBY(A1:A5, B1:B5, -1) 50

errors

error values observed from the engine — each with a call that produces it.

errorproduced by
#ERROR! =SORTBY(A2:A3,B2:B3,1,C2:C3)

related

  • ARRAY_CONSTRAIN truncates a range to at most the given rows and columns
  • ARRAYFORMULA evaluates an expression across a range (this engine already spills, so it is a pass-through for sheets compatibility)
  • ARRAYTOTEXT converts array to text representation
  • BYCOL applies lambda to each column of array
  • BYROW applies lambda to each row of array
  • CHOOSECOLS returns the specified columns from an array