TH2.5 top-nested for Frequency Analysis
Finding the rare in the frequent
Most sign-ins are from known IPs accessing known applications. The interesting signal is in the exceptions: the one IP an individual user has never used before, the one application accessed from an anomalous location, the one device that appeared for a single session.
top-nested performs hierarchical frequency analysis. It finds the top N values at each level of a hierarchy, preserving the parent-child relationship. This is more powerful than summarize | top because it shows you the rare items within each group — not just the globally rare items.
Basic top-nested for sign-in profiling
| |
Hunting application: rare application access patterns
| |
Finding rare combinations with top-nested + where
| |
Figure TH2.5 — Flat versus nested frequency analysis. Flat top-N misses per-entity anomalies. top-nested reveals them.
Try it yourself
Exercise: Profile application access by country
Run the second query (top 20 apps, top 5 countries per app) against your environment. Examine the results for each application: are the countries expected for your organization's user base?
If an application normally accessed from 2–3 countries suddenly shows access from a 4th country, note it as a potential hunting lead. Cross-reference with the authentication anomaly patterns from TH2.1 — is the user from that country a new IP in their baseline?
The myth: Standard summarize and top operators provide the frequency analysis hunting needs.
The reality: summarize | top produces flat rankings — the most common values globally. It does not answer “what is unusual for this specific entity?” which is the core hunting question. top-nested provides the hierarchical view: for each entity, what are its most (and least) common behaviors? The rare behaviors within each entity’s profile are the hunting signals. Flat analysis finds globally unusual values. Nested analysis finds per-entity unusual values. Hunting needs both, but per-entity analysis is the higher-value pattern.
Extend this operator
top-nested supports `with others` to include a catch-all group for values outside the top N. This is useful for identifying what percentage of an entity's activity falls outside the top patterns: `top-nested 3 of IPAddress with others = "Other" by Count = count()`. If "Other" accounts for a significant percentage, the entity has diverse behavior that the top 3 do not adequately represent — and the "Other" category may contain the anomaly.
References Used in This Subsection
- Microsoft. “KQL top-nested Operator.” Microsoft Learn. https://learn.microsoft.com/en-us/kusto/query/top-nested-operator
- Course cross-references: TH4 (per-user IP profiling), TH6 (per-app access profiling), TH7 (per-role activity profiling)
You're reading the free modules of this course
The full course continues with advanced topics, production detection rules, worked investigation scenarios, and deployable artifacts. Premium subscribers get access to all courses.