Search code examples
azure-application-insightskql

Application Insights Kusto (KQL): How to sort items produced by make_set operator


I'm trying to group different kinds by a version. Here is the simplest repro/example:

let Source = datatable(Name:string, Version:string)
[
    'Car', '1.0.0',
    'Train', '2.0.0',
    'Train', '1.0.0',
    'Car', '2.0.0'
];
Source
| summarize make_set(Name) by Version

Right now the the kinds appear according to the order of individual records:

enter image description here

As a result it is hard to compare lines. Wonder how to make items sorted in make_set.


Solution

  • You could use array_sort_asc() / array_sort_desc():

    For example:

    let Source = datatable(Name:string, Version:string)
    [
        'Car', '1.0.0',
        'Train', '2.0.0',
        'Train', '1.0.0',
        'Car', '2.0.0'
    ];
    Source
    | summarize Names = array_sort_asc(make_set(Name)) by Version