Use the array_sort_desc function in APL to sort the elements of an array in descending order. This function is especially useful when working with numerical data or categorical data where you want to prioritize higher values first—such as showing the longest durations, highest response times, or most severe error codes at the top of an array.

You can use array_sort_desc in scenarios where ordering matters within grouped aggregations, such as collecting response times per user or span durations per trace, and then sorting them to identify the highest or most impactful values.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.

Usage

Syntax

array_sort_desc(array)

Parameters

NameTypeRequiredDescription
arrayarray✔️The input array whose elements are sorted descending.

Returns

If the input is a valid array, the function returns a new array with its elements sorted in descending order. If the array is empty or contains incompatible types, it returns an empty array.

Example

Query

['sample-http-logs']
| project sort = array_sort_desc(dynamic(['x', 'a', 'm', 'o', 'i']))

Run in Playground

Output

[
  [
    "x",
    "o",
    "m",
    "i",
    "a"
  ]
]
  • array_index_of: Returns the index of a value in an array. Useful after sorting to locate specific elements.
  • array_length: Returns the number of elements in an array. Useful for measuring the size of arrays before or after sorting.
  • array_slice: Extracts a range of elements from an array. Use it after sorting to get the top N or bottom N values.
  • array_sort_asc: Sorts an array in ascending order. Use this when you want to prioritize smaller values first.