RANKX Function
Description:
The RANKX function returns the rank of an expression in the list of values for each row in the table argument.
Return Value:
RANKX returns a single integer value, representing the rank number of values among all possible values of expression.
Syntax:
RANKX( <table>,<expression>[,<value>[,<order>[,<ties>]]] )
- Description of the parameters:
PARAMETER |
DESCRIPTION |
---|---|
Table |
DAX expression that returns a table |
Expression |
The expression is evaluated for each row of table |
Value |
DAX expression that returns a single scalar value whose rank is to be found. Optional |
Order |
Value that specifies how to rank value. Optional |
Ties |
An enumeration that defines how to determine ranking when there are ties. Optional |
Example:
In this example, we want to add a measure that calculates the sales amount ranking for each product subcategory in the Product SubCategory table.
The following formula shows how to add a rank measure, that displays the rank of each Product Sub Category by Sales amount in descending order
Rank = RANKX(
ALL(ProductSubcategory[ProductSubcategory]),
[SumSalesAmount],,DESC
)
Note that:
- When the value parameter is omitted, the value of expression at the current row is used instead.
- Optional arguments might be skipped by placing an empty comma (,) in the argument list.
- The default value for the Order argument is DESC.
- The default value for the Ties argument is SKIP.
Related Video: