top

top N by X returns the N rows with the largest values of X, already sorted. It is a shorter way to write sort by X | take N:

SigninLogs
| summarize Failures = count() by IPAddress
| top 10 by Failures

Like sort by, top is descending by default. Add asc for the smallest values: top 5 by Failures asc.

Ties

If several rows share the value at the cut-off, top keeps only as many as you asked for, and which of the tied rows survive is not defined. top 1 by Failures may hide a second IP address with exactly the same number of failures. When ties are possible and matter, use sort by and look at a few more rows, or filter with a threshold instead (where Failures >= 20).

top or arg_max()?

top works on the whole table: top 1 by TimeGenerated gives the single latest row overall. To get the latest row for each user or device, use arg_max() in summarize.

top or take?

take returns any N rows, with no sorting at all. Use top when you mean “the biggest” or “the most recent”.

Examples

1 The two most frequent programs
DeviceProcessEvents
| summarize Runs = count() by FileName
| top 2 by Runs

Programs three to seven all ran exactly 261 times, so a top 5 here would have to pick among tied rows.

2 The three most recent failed logons
SecurityEvent
| where EventID == 4625
| top 3 by TimeGenerated
| project TimeGenerated, Computer, TargetUserName, IpAddress
3 The smallest values with asc
SigninLogs
| summarize SignIns = count() by AppDisplayName
| top 3 by SignIns asc

Practice it