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
Examples
SigninLogs
| summarize SignIns = count(), Users = dcount(UserPrincipalName) by AppDisplayNameSecurityEvent
| summarize count(), min(TimeGenerated) by Computer, EventIDUnnamed aggregates get names like count_ and min_TimeGenerated.
DeviceNetworkEvents
| where isnotempty(RemoteUrl)
| summarize FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated), Connections = count() by RemoteUrl
| sort by Connections descPractice it
- #01Find the IP behind a password sprayeasy
- #02Complete the query: brute force against a servermedium
- #03Spot impossible travel: two countries in one hourmedium
- #04Size up a password spray from one IPeasy
- #06Failed sign-ins by client app, most firsteasy
- #07Which account names did the attacker try?easy
- #08When did the brute force start and stop?medium
- #10Complete the query: guesses at accounts that don't existmedium
- #14Find the one-device destination with hundreds of connectionsmedium
- #15Successful sign-ins from countries that almost never appearmedium
+ 16 in the full SC-200 set · all exercises