<!-- https://learnsql.cpetoday.com/functions/dax/rank -->
# RANK

Language: DAX
Category: Ranking and windows
Syntax: RANK(...) (argument list depends on your version. Check the current Microsoft DAX reference before you use it.)
Summary: A newer DAX function that ranks items in an ordered set of rows. Its exact arguments depend on the version you use.
Returns: A whole number (the rank).
Level: Advanced
Related: RANKX, WINDOW, OFFSET, INDEX, ROWNUMBER, TOPN

## What it does
RANK is one of the newer DAX functions that work on an ordered set of rows. It belongs to the same family as WINDOW, OFFSET, INDEX and ROWNUMBER. It gives each item a position based on an ordering you choose, such as sales from highest to lowest. For ranking in a model today, `RANKX` is the established function with well-known arguments, and most finance models use it.

This page does not show RANK code, because the exact argument list could not be confirmed from the reference material available for this page. Check the Microsoft DAX reference for your version before you depend on RANK.

## Syntax and arguments
The arguments depend on the version. Read the current documentation for the order to use, which rows form the set, and how ties are handled.

## Example
The same question, answered with the established function: the rank of each product by sales, among the products the user has selected.

```dax
Product Rank =
RANKX (
    ALLSELECTED ( Product[ProductName] ),
    [Total Sales],
    ,
    DESC,
    DENSE
)
```

In a table with one row per product, each row shows its position among the selected products. The same business question can be answered with RANK once you have confirmed its arguments for your version.

## Things to watch
- Confirm the arguments and the version support before you use the function in a shared report.
- Test the ties behavior with a few rows where two values are equal.
- Rank numbers are not additive. Do not sum them.
- Keep a test visual with the ranks you expect, so a later change shows up.

## In business terms
Ranking vendors by spend, customers by receivables, or branches by margin. The business use is the same as for `RANKX`: a position that reviewers can read at a glance.
