azure-application-insightsms-app-analytics

Application Insights Analytics doing sub selects


I am using this reference documentation for Application Insights.

How can I do a sub-select using the output of a different query?

//Query 1
Events 
| where  Timestamp >= ago(30min) and Data contains('SomeString')
| project TraceToken

//I would like to use the first query's output in the subselect here.
Events 
| where TraceToken in ({I would like to use the First query's output here.})

Is a join better in this scenario. Which would have better performance.


Solution

  • You can use let statement to achieve this.

    Here is an example from the Analytics documentation, I hope this helps:

    let topCities =  toscalar ( // convert single column to value
       requests
       | summarize count() by client_City 
       | top 4 by count_ 
       | summarize makeset(client_City));
    requests
    | where client_City in (topCities) 
    | summarize count() by client_City;
    

    Edit: By default the maximum number of elements returned by the makeset() function is 128. The MaxSetSize should be specified for larger dataSets.