Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions data-explorer/kusto/query/rowrankfunction.md
Original file line number Diff line number Diff line change
@@ -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