Use the asOrder() serialization function to specify the sort order in a SAQL query.
Let’s look at an example where the selection in a toggle widget determines the sort order in a SAQL query.
Given this data from a source query:
[
{order: "first", direction: "desc"}
{order: "second", direction: "asc"}
]
To order by a single field, apply this order logic. When you don’t specify the direction in the query, the default is ascending.
q = order q by {{cell(stepFoo.selection, 1, "order").asOrder()}};
After CRM Analytics evaluates the interaction, the grouping becomes:
q = order q by 'second';
To order by multiple fields, use this grouping logic.
q = order q by {{column(stepFoo.selection, ["order"]).asOrder()}};
After CRM Analytics evaluates the interaction, the grouping becomes:
q = order q by ('first', 'second');
To specify the order and the direction, use this grouping logic.
q = order q by {{row(stepFoo.selection, [], ["order", "direction"]).asOrder()}};
After CRM Analytics evaluates the interaction, the grouping becomes:
q = order q by ('first' desc, 'second' asc);