Skip to main content

Sort by

Overview​

The sort parameter controls the ordering of your query results. You can sort by any column (metrics or properties) included in your columns parameter.

Parameters​

ParameterDescriptionValuesRequired
sortArray of column names to sort byArray of strings (with optional - prefix)No

Sorting Rules​

  • Ascending order: Use column name directly (e.g., "device_type")
  • Descending order: Prefix column name with - (e.g., "-m_visits")
  • Multiple sorts: Order matters - first item has highest priority
  • Column requirement: Can only sort on columns present in the columns parameter

Examples​

Example 1: Simple ascending sort​

Sort results by device type in ascending order.

{
"columns": ["device_type", "m_visits"],
"sort": ["device_type"]
}

Example 2: Descending sort by metric​

Sort results by visits in descending order (highest first).

{
"columns": ["device_type", "m_visits"],
"sort": ["-m_visits"]
}

Example 3: Multiple column sorting​

Sort by country (descending), then device type (ascending), then visits (descending), then users (ascending).

{
"columns": ["geo_country", "device_type", "m_visits", "m_users"],
"sort": [
"-geo_country",
"device_type",
"-m_visits",
"m_users"
]
}