Stage 02 · Aggregation & Visualization — Turn rows into insight
Goal: group, count, and chart data with
summarize,bin(), andrender, then correlate across event types withunionandjoin. Prerequisite:DemoIdentityLogsfrom Stage 00. All queries run against it.
1. summarize— the workhorse
summarize collapses many rows into grouped aggregates. Pattern: summarize <Aggregation> by <GroupingColumns>.
// Failed sign-ins per user
DemoIdentityLogs
| where EventType == "Signin"
| where ResultType != 0
| summarize FailureCount = count() by UserPrincipalName
| sort by FailureCount desc
Group by multiple columns to slice finer:
// Failures per user AND source IP — surfaces where the attempts came from
DemoIdentityLogs
| where EventType == "Signin"
| where ResultType != 0
| summarize FailureCount = count() by UserPrincipalName, IPAddress
| sort by FailureCount desc
Reference: summarize operator · Aggregation functions
2. The aggregation functions you'll use most
| Function | What it gives you | Example |
|---|---|---|
count() |
number of rows in the group | summarize n = count() by UserPrincipalName |
countif(pred) |
conditional count | summarize Fails = countif(ResultType != 0) by UserPrincipalName |
dcount(col) |
approx. distinct values | summarize Apps = dcount(AppDisplayName) by UserPrincipalName |
arg_max(t, *) |
the whole row with the max of t |
summarize arg_max(TimeGenerated, *) by UserPrincipalName |
make_set(col) |
de-duplicated list | summarize IPs = make_set(IPAddress) by UserPrincipalName |
make_list(col) |
list keeping duplicates/order | summarize Ops = make_list(OperationName) by UserPrincipalName |
// Distinct apps each user FAILED against (>1 hints at spray / probing)
DemoIdentityLogs
| where EventType == "Signin"
| where ResultType != 0
| summarize DistinctApps = dcount(AppDisplayName) by UserPrincipalName
| where DistinctApps > 1
| sort by DistinctApps desc
// Latest sign-in record per user (arg_max carries all columns via *)
DemoIdentityLogs
| where EventType == "Signin"
| summarize arg_max(TimeGenerated, *) by UserPrincipalName
| project UserPrincipalName, TimeGenerated, ResultType, IPAddress, Location, AppDisplayName
// make_set = de-duplicated (which IPs?) vs make_list = every occurrence, in order
DemoIdentityLogs
| where EventType == "Signin"
| summarize DistinctIPs = make_set(IPAddress), IPsInOrder = make_list(IPAddress) by UserPrincipalName
Compare the two columns for alexw: DistinctIPs collapses to ["52.170.12.45","185.220.101.2"], while IPsInOrder keeps every attempt — so the repeated 185.220.101.2 failures are visible as a run.
make_setremoves duplicates (good for "which IPs?");make_listkeeps every occurrence in order (good for "the sequence of actions").
3. Time bucketing with bin()
bin(column, size) rounds values down to a fixed interval — essential for time series.
// Sign-in failures per hour
DemoIdentityLogs
| where EventType == "Signin" and ResultType != 0
| summarize Failures = count() by bin(TimeGenerated, 1h)
Change the size to suit the span: 5m, 1h, 1d. Reference: bin()
4. Charts with render
Append render to draw the result inline. The first column decides the X-axis; numeric columns are the values.
// Bar chart: failures by user
DemoIdentityLogs
| where EventType == "Signin" and ResultType != 0
| summarize Failures = count() by UserPrincipalName
| sort by Failures desc
| render barchart
// Time chart: failures over time
DemoIdentityLogs
| where EventType == "Signin" and ResultType != 0
| summarize Failures = count() by bin(TimeGenerated, 1h)
| render timechart
// Pie chart: share of attempts by application
DemoIdentityLogs
| where EventType == "Signin"
| summarize Count = count() by AppDisplayName
| render piechart
// Multi-series: success vs failure on one time chart.
// A string column (Outcome) after the numeric column splits it into series.
DemoIdentityLogs
| where EventType == "Signin"
| extend Outcome = iff(ResultType == 0, "Success", "Failure")
| summarize Count = count() by bin(TimeGenerated, 1h), Outcome
| render timechart
Shape matters for charts. Timechart = first column
datetime, then a numeric, then (optionally) one string column for series. Barchart/piechart = first column the category, second column numeric. Reduce to the columns the chart needs withproject. Reference: render operator
5. Combining tables: union
union stacks rows from multiple sources. In the demo set, both event types live in one table, so we filter — but the same syntax works across real tables (SigninLogs | union AuditLogs).
// A unified activity feed: who did what, when — from both event types
DemoIdentityLogs
| where EventType == "Signin"
| project TimeGenerated, Actor = UserPrincipalName, Action = strcat("Sign-in: ", ResultDescription), Source = IPAddress
| union (
DemoIdentityLogs
| where EventType == "Audit"
| project TimeGenerated, Actor = UserPrincipalName, Action = OperationName, Source = AuditResult
)
| sort by TimeGenerated desc
Reference: union operator
6. Correlating with join
join matches rows across two result sets on a key. This is how you connect failed logins to admin activity by the same user — the heart of detection.
// Users with >1 failed sign-in who ALSO performed admin operations
let FailedUsers =
DemoIdentityLogs
| where EventType == "Signin" and ResultType != 0
| summarize FailureCount = count() by UserPrincipalName
| where FailureCount > 1;
DemoIdentityLogs
| where EventType == "Audit"
| join kind=inner FailedUsers on UserPrincipalName
| project TimeGenerated, UserPrincipalName, OperationName, AuditResult, FailureCount
| sort by TimeGenerated desc
Join flavours you'll meet: inner (only matches), leftouter (all left + matches — enrichment), leftanti (left rows with no match — "find what's missing"). Full treatment in Stage 03.
Reference: join operator
Exercises
- Count total vs failed sign-ins per user in a single
summarize(hint:count()+countif()). - Build a bar chart of the top audit operations by frequency.
- For each user, list the set of countries (
Location) they signed in from. - Plot sign-in failures per hour, but only for
alexw@contoso.com.
🎯 Check yourself (against the seeded
DemoIdentityLogs): 1 → 5 users,alexwhighest with 10 failed,sophial6,jamest1,meganb/itadmin0. 2 → "Add member to group" tops the bar chart. 3 → onlyalexwshows two countries (United States,Netherlands); everyone else one. 4 → a cluster of failure bars on the attack days, none for the quiet days.
Answers
// 1
DemoIdentityLogs
| where EventType == "Signin"
| summarize Total = count(), Failed = countif(ResultType != 0) by UserPrincipalName
| sort by Failed desc
// 2
DemoIdentityLogs
| where EventType == "Audit"
| summarize Count = count() by OperationName
| sort by Count desc
| render barchart
// 3
DemoIdentityLogs
| where EventType == "Signin"
| summarize Countries = make_set(Location) by UserPrincipalName
// 4
DemoIdentityLogs
| where EventType == "Signin" and ResultType != 0 and UserPrincipalName == "alexw@contoso.com"
| summarize Failures = count() by bin(TimeGenerated, 1h)
| render timechart
You'll know you've completed Stage 02 when you can
- pick the right aggregate (
count/countif/dcount/make_set/arg_max) for a question; - bucket time with
bin()and chart it with the correctrendershape; - stack sources with
unionand correlate them with ajoin(and name the join flavour you used); - explain
make_setvsmake_listand when each matters.
Next: Stage 03 · Advanced — parsing dynamic data, modular let, ASIM parsers, and visualization shaping on the real tables.
Mission 02 challenge
In SigninLogs, count each user's failed sign-ins in the last day and show the five users with the most.
Write it in the box below and check it. Then compare with one answer; others can be right too.
Show one answer
SigninLogs
| where TimeGenerated > ago(1d)
| where ResultType != "0"
| summarize Failures = count() by UserPrincipalName
| top 5 by FailuresCheck your own query
Write a variation of this lesson's queries, on the practice table DemoIdentityLogs or a real table, and check it against the real schema.
Course by Kaushik Saha. Source: sentinel/kql/02-aggregation-viz/README.md at ea5adab001fa. Queries checked with Microsoft.Azure.Kusto.Language 12.4.1 against schema bundle 2026.10.29.