sum() / avg() / min() / max()

These four aggregates go inside summarize and compute one value per group:

Function Returns Default column name
sum(x) the total of x sum_x
avg(x) the average of x, as a decimal (real) avg_x
min(x) the smallest value of x min_x
max(x) the largest value of x max_x

sum() and avg() need numbers. min() and max() also work on dates and strings, and on dates they are the everyday way to find first seen and last seen times:

SigninLogs
| summarize FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by IPAddress

Subtracting the two gives a time span, the duration of the activity: extend Duration = LastSeen - FirstSeen.

Things to know

  • Null values are skipped. The average of 2, null and 4 is 3, not 2.
  • max() gives you the largest value, but not the rest of that row. To see, for example, the IP address of a user’s latest sign-in, use arg_max().
  • avg() of whole numbers is a decimal: the average of 1 and 2 is 1.5.

Examples

1 First and last event in the table
SigninLogs
| summarize Earliest = min(TimeGenerated), Latest = max(TimeGenerated)

min() and max() work on dates, which is the quickest way to see the time range of a table.

2 Statistics over a per-device count
DeviceNetworkEvents
| summarize Connections = count() by DeviceName
| summarize avg(Connections), min(Connections), max(Connections), sum(Connections)

A second summarize works on the result of the first. The default names are avg_Connections and so on.

3 Logon types per server
SecurityEvent
| where EventID == 4624
| summarize Lowest = min(LogonType), Highest = max(LogonType), Average = avg(LogonType) by Computer

Practice it