diff --git a/data-explorer/kusto/query/rowrankfunction.md b/data-explorer/kusto/query/rowrankfunction.md new file mode 100644 index 0000000000..ad9728a653 --- /dev/null +++ b/data-explorer/kusto/query/rowrankfunction.md @@ -0,0 +1,52 @@ +--- +title: row_rank() - Azure Data Explorer | Microsoft Docs +description: This article describes row_rank() in Azure Data Explorer. +services: data-explorer +author: royo +ms.author: royo +ms.reviewer: alexans +ms.service: data-explorer +ms.topic: reference +ms.date: 01/28/2021 +--- +# row_rank() + +Returns the current row's rank in a [serialized row set](./windowsfunctions.md#serialized-row-set). +The row index starts by default at `1` for the first row, and is incremented by `1` whenever the provided *Term* is different than the previous row's *Term*. + +## Syntax + +`row_rank` `(` *Term* `)` + +* *Term* is is an expression indicating the value to consider for the rank. The rank is increased whenever the *Term* changes. + +## Returns + +The function returns the row rank of the current row as a value of type `long`. + +## Example + +This example shows how one can rank the `Airline` by the number of departure from the *SEA* `Airport`: + +```kusto +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(Departures) +``` + +Running this query produces the following result: + +Airport | Airline | Departures | Rank +---------|----------|-------------|------ +SEA | BA | 2 | 1 +SEA | LH | 3 | 2 +SEA | UA | 3 | 2 +SEA | EL | 3 | 2 +SEA | LY | 100 | 3 \ No newline at end of file