summarize

summarize groups rows and computes one or more aggregates for each group. It is the KQL version of SQL’s GROUP BY, written in one step:

SigninLogs
| summarize Failures = count() by IPAddress

Read it as: for each IPAddress, count the rows. The result has one row per group, with the by columns first and the aggregates after them. Without by, you get a single row for the whole table.

Aggregation functions

count(), countif(), dcount(), dcountif(), sum(), avg(), min(), max(), arg_max(), arg_min() and make_set(), make_list(). You can use several in one summarize, separated by commas.

Column names

If you don’t name an aggregate, Kusto names it for you: count() becomes count_, dcount(IPAddress) becomes dcount_IPAddress, avg(Duration) becomes avg_Duration, and so on. Later operators must use those exact names (sort by count_). Naming them yourself (Failures = count()) is clearer.

Grouping by time

Group by bin() to count per hour, per day, or any other interval: summarize count() by bin(TimeGenerated, 1h). The column keeps the name TimeGenerated, unless you name it (by Hour = bin(TimeGenerated, 1h)).

Things to know

  • Only the by columns and the aggregates survive. Any other column is gone after summarize. To keep a whole row, use arg_max().
  • The result rows come back in no particular order; add sort by after it.
  • You can summarize twice: first per user, then count the users per band.

Examples

1 Sign-ins and distinct users per app
SigninLogs
| summarize SignIns = count(), Users = dcount(UserPrincipalName) by AppDisplayName
2 Default column names when you don't name them
SecurityEvent
| summarize count(), min(TimeGenerated) by Computer, EventID

Unnamed aggregates get names like count_ and min_TimeGenerated.

3 First and last time each website was contacted
DeviceNetworkEvents
| where isnotempty(RemoteUrl)
| summarize FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated), Connections = count() by RemoteUrl
| sort by Connections desc

Practice it