Order
  • 27 May 2022
  • 1 Minute to read
  • Dark
    Light
  • PDF

Order

  • Dark
    Light
  • PDF

Sorts a list using a formula that is evaluated for each item in the list. Returns the sorted list.

The formula should result to a comparable value (a text or a number) that is used to determine the order of the items. By default the items are sorted in ascending order. By providing the 3rd parameter you can choose the direction.

If multiple values have the same ordering value, their original order will be preserved.

Note that for text values, the ordering is case-sensitive. If you want a case-insensitive ordering, you may for example wrap your ordering formula with LOWERCASE function.

Function signature

ORDER(list: Array, sortingcriteria: Function, sortdirection: String = asc) => Array
Parameter Description
List List of items to sort
Sorting criteria Formula evaluated for each item in the list, used to determine the ordering value for the item
Sort direction Direction of the ordering. Use either "asc" meaning ascending order (smallest first) or "desc" meaning descending order (greatest first).

Examples

animals = [
  {
    "name": "dog",
    "weight": 123
  },
  {
    "name": "cat",
    "weight": 48
  },
  {
    "name": "rat",
    "weight": 10
  },
  {
    "name": "pig",
    "weight": 123
  }
]
Formula Return value
ORDER(animals, item.weight) [{"name":"rat","weight":10},{"name":"cat","weight":48},{"name":"dog","weight":123},{"name":"pig","weight":123}]
ORDER(animals, item.weight, "desc") [{"name":"dog","weight":123},{"name":"pig","weight":123},{"name":"cat","weight":48},{"name":"rat","weight":10}]
ORDER<animal>(animals, animal.weight, "asc") [{"name":"rat","weight":10},{"name":"cat","weight":48},{"name":"dog","weight":123},{"name":"pig","weight":123}]

Was this article helpful?

What's Next