Add a row with total in Log Analytics Kusto query

Viewed 214

I query a request log for a summary of status codes. However I would like to add a row at the end of the results, showing the total number of requests. How do I add such a row?

Current query (simplified)

MyLog
| summarize count() by responseCode

Current result looks like

responseCode count
200 1000
404 20
500 100

I would like to have the totals like this

responseCode count
200 1000
404 20
500 100
total 1120
1 Answers

you could try this:

MyLog
| summarize c = count() by responseCode
| as hint.materialized=true T
| union (T | summarize c = sum(c) by responseCode = "total")

or this:

MyLog
| summarize c = count() by responseCode
| union (print responseCode = "total", c = toscalar(MyLog | count))
Related