SORT sorts a collection by the values returned from applying a sorting function to each element in the collection.

Function category: Collection


SORT(arg1, arg2)




A key function. Each element of the collection is passed to that function and then sorted based on the function's result. An underscore ( _ ) represents a placeholder, which is the value itself (dynamic reference).


A collection to be sorted.


Let's say we're given a response with the following vehicle information:

"fleet_prices": [16000, 17450, 9200],
"fleet_names": ["BMW", "Audi", "Mercedes Benz"]

Example 1: Sort prices by numerical value

If we want to organize these prices by basic numerical value, we can use SORT with the dynamic references themselves serving as a sorting function.

# Sort prices using dynamic references
SORT(_, data.fleet_prices)
# Returns [9200, 16000, 17450]

Example 2: Sort strings using same arguments

We can also sort strings using SORT with dynamic references.

# Sort strings using dynamic references
SORT(_, data.fleet_names)
# Returns ["Audi", "BMW", "Mercedes Benz"]

Example 3: Sort using a dynamic reference

We can also apply a function such as LEN to the dynamic reference. This sorts by length of string.

# Sort strings using the LEN function with dynamic references
SORT(LEN(_), data.fleet_names)
# Returns ["Mercedes Benz", "Audi", "BMW",]