Search code examples
azureazure-application-insights

How to "Group By" by result and count in Azure App Insights


I'm trying to group some results I have in app insights and am struggling

If I were to tabulate my results, it would look like

Product        Version

 A              1
 B              2
 A              2
 A              1
 B              3
 B              3

As you can see, I have 2 products (A and B), and each has a version number.

I am trying to group these and provide a count, so my end result is

Product        Version       Count

 A              1              2
 A              2              1 
 B              2              1
 B              3              2

At the moment, my approach is a mess because I am doing this manually with

customEvents
| summarise A1 = count(customEvents.['payload.prod'] == "A" and myEvents.['payload.vers'] == "1"),
| summarise A2 = count(customEvents.['payload.prod'] == "A" and myEvents.['payload.vers'] == "2")

I have no idea how I can aggregate these so it can group by product and version and then count the occurrences of each


Solution

  • I think your are looking for:

    customEvents
    | extend Product = tostring(customDimensions.prod) 
    | extend MajorVersion = split(customDimensions.Version, ".")[0] 
    | summarize Count = count() by Product , tostring(MajorVersion) 
    

    I wrote this off the top off my head so there might be some syntax issues. I assumed prod and vers are in the customdimensions, let me know if it is otherwise.

    You can summarize by multiple fields as you can see.