row_rank_min()

Switch services using the Version drop-down list. Learn more about navigation.
Applies to: ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel

Returns the current row's minimal rank in a serialized row set.

The rank is the minimal row number that the current row's Term appears in.

Syntax

row_rank_min ( Term, [restart] )

Learn more about syntax conventions.

Parameters

Name Type Required Description
Term string ✔️ An expression indicating the value to consider for the rank. The rank is the minimal row number for Term.
restart bool Indicates when the numbering is to be restarted to the StartingIndex value. The default is false.

Returns

Returns the row rank of the current row as a value of type long.

Examples

The following query shows how to rank the Airline by the number of departures from the SEA Airport.

datatable (Airport:string, Airline:string, Departures:long)
[
  "SEA", "LH", 3,
  "SEA", "LY", 100,
  "SEA", "UA", 3,
  "SEA", "BA", 2,
  "SEA", "EL", 3
]
| sort by Departures asc
| extend Rank=row_rank_min(Departures)

Output

Airport Airline Departures Rank
SEA BA 2 1
SEA LH 3 2
SEA UA 3 2
SEA EL 3 2
SEA LY 100 5

The following query shows how to calculate the rank of each Item partitioned by Category.

datatable(Category:string, Item:string, Value:int)
[
    "A", "item1", 10,
    "A","item2", 10,
    "A", "item3", 5,
    "A", "item4", 20,
    "B", "item2", 5,
    "B", "item1", 7
]
| sort by Category asc, Value asc
| extend rank = row_rank_min(Value, Category != prev(Category))

Output

Category Item Value rank
A item3 5 1
A item1 10 2
A item2 10 2
A item4 20 4
B item2 5 1
B item1 7 2