Skip to content

Sorting

Sorting determines the order of rows in a report's resulting table. Sorting by one or more fields is supported.

Basic syntax

Sorting is defined as an array of objects in the sorting parameter:

json
{
  "sorting": [
    {"field": "cost", "direction": "desc"},
    {"field": "campaign_name", "direction": "asc"}
  ]
}

Sorting parameters

ParameterTypeDescription
fieldstringThe field name: a dimension or a metric
directionstringDirection: asc (ascending) or desc (descending)

Directions

DirectionBehavior for numbersBehavior for stringsBehavior for dates
ascSmallest to largestA → Z, a → zEarliest to latest
descLargest to smallestZ → A, z → aLatest to earliest

Multi-field sorting

When multiple fields are specified, sorting is applied sequentially:

json
{
  "sorting": [
    {"field": "date", "direction": "desc"},
    {"field": "cost", "direction": "desc"}
  ]
}

Rows are first sorted by date (newest on top), then within the same date — by cost (largest on top).

Default sorting

If sorting isn't specified, the default sorting applies:

  • If there's a date dimension: by date desc
  • If there are dimensions without a date: by the first dimension asc
  • If there are no dimensions: no sorting (source order)

Special cases

NULL values

NULL values always come last regardless of sort direction:

  • asc: values → NULL
  • desc: values → NULL

Calculated metrics

Sorting by calculated metrics is supported:

json
{
  "calculated_metrics": [
    {"name": "cpl", "formula": "[cost] / [leads]"}
  ],
  "sorting": [
    {"field": "cpl", "direction": "asc"}
  ]
}

Monetary values

Sorting by monetary metrics (money) is done by the numeric value in the source's currency, not by the formatted string.

Case sensitivity

String sorting is case-insensitive: "A" and "a" are treated as equal.

Limitations

  • A maximum of 3 sort fields per report
  • You can't sort by fields that aren't included in the report

Maintained by the LightLead Documentation Team · Last verified: 2026-07-25