top-hitters operator
Learn how to use the top-hitters operator to return an approximation for the most popular distinct values in the input.
Returns an approximation for the most popular distinct values, or the values with the largest sum, in the input.
Syntax
T | top-hitters NumberOfValues of ValueExpression [ by SummingExpression ]
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| T | string | ✔️ | The input tabular expression. |
| NumberOfValues | int, long, or real | ✔️ | The number of distinct values of ValueExpression. |
| ValueExpression | string | ✔️ | An expression over the input table T whose distinct values are returned. |
| SummingExpression | string | If specified, a numeric expression over the input table T whose sum per distinct value of ValueExpression establishes which values to emit. If not specified, the count of each distinct value of ValueExpression is used instead. |
Examples
The examples in this section show how to use the syntax to help you get started.
Get top 2 events by totals
This example summarizes storm event data by calculating the total number of events for each event type. The query then selects the top two event types with the highest total number of events.
StormEvents
| summarize TotalEventId = sum(EventId) by EventType
| top 2 by TotalEventId desc
Output
| EventType | TotalEventId |
|---|---|
| Thunderstorm Wind | 562,509,013 |
| Hail | 474,690,007 |
Get most frequent items
StormEvents
| top-hitters 5 of EventType
Output
| EventType | approximate_count_EventType |
|---|---|
| Thunderstorm Wind | 13015 |
| Hail | 12711 |
| Flash Flood | 3688 |
| Drought | 3616 |
| Winter Weather | 3349 |
Get top hitters based on column value
This example shows how to find the States with the most Thunderstorm Wind events.
StormEvents
| where EventType == "Thunderstorm Wind"
| top-hitters 10 of State
Output
| State | approximate_sum_State |
|---|---|
| TEXAS | 830 |
| GEORGIA | 609 |
| MICHIGAN | 602 |
| IOWA | 585 |
| PENNSYLVANIA | 549 |
| ILLINOIS | 533 |
| NEW YORK | 502 |
| VIRGINIA | 482 |
| KANSAS | 476 |
| OHIO | 455 |
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.