Search code examples
azure-application-insightsms-app-analytics

Application Insights order by aggregate


I have the following query:

customEvents
| summarize count(datepart("Second", timestamp) ) 
    by toint(customMeasurements.Latency)

This is counting the number of seconds past the minute and grouping it by an integer Latency.

How do I add an order by operator to this to order by these columns?


Solution

  • In order to do this you need to alias the columns.

    Aliasing columns is performed by prefixing the value with column_alias=.

    customEvents
    | summarize Count=count(datepart("Second", timestamp) ) 
        by Latency=toint(customMeasurements.Latency)
    

    Then we can reference the columns by their aliases:

    customEvents
    | summarize Count=count(datepart("Second", timestamp) ) 
        by Latency=toint(customMeasurements.Latency)
    | order by Latency asc nulls last