ThenBy (PQL)

Is used to apply secondary sorting to a previously ordered list. It refines an existing sort order by adding an additional criterion

  • Returned Output: List
  • Library: PQL \ Semantic \ List
  • Version: 2025.00.000
  • Compatibility: Pyramid Query Language (PQL) data sources

Syntax

thenBy( <List> , <Data Point> , <Flag> )

* Click on the function's arguments above for more details on the input values.

Comments
  • The list is pre-sorted by another order function first.
  • The numeric datapoint is used to sort the list within the context of the first sort, where there are numeric ties.
  • For details on how to employ and use this function see the semantic calculation overview.
Different Function types

This function is related to the ORDER function.

ThenBy Order Flags

ASC (Ascending) or DESC (Descending) will order the list from low to high, or high to low. The ranking mechanism of the first Order formulation (listed above) is based on the elements' labels, so it's alphabetical. The ranking mechanism of the second formulation uses the numeric data point for each element to provide the ordering.

Examples

In this example, we sort all countries first by sales ascending, and then sort them by cost descending, where there are numerical ties on sales.

Thenby(order([customer].[country].allmembers, [measures].[sales], asc),[measures].[cost], desc)