RANKX

Updated on

RANKX is a DAX function that returns the rank of an expression evaluated in the current context within a list of values for that expression.

Syntax

RANKX(
   Table,
   Expression,
   Value,
   Order,
   Ties
)
Argument Properties Description
Table A table expression.
Expression An expression that will be evaluated for row of the table.
Value Optional An expression that will be evaluated in the current context. If omitted, the Expression argument will be used.
Order Optional The order to be applied. 0/FALSE/DESC – descending; 1/TRUE/ASC – ascending.
Ties Optional Function behavior in the event of ties. Skip – ranks that correspond to elements in ties will be skipped; Dense – all elements in a tie are counted as one.

Return Values

The rank number of value among all possible values of expression evaluated for all rows of table numbers.

Remarks

  • If expression or value evaluates to BLANK it is treated as a 0 (zero) for all expressions that result in a number, or as an empty text for all text expressions.

  • If value is not among all possible values of expression then RANKX temporarily adds value to the values from expression and re-evaluates RANKX to determine the proper rank of value.

  • Optional arguments might be skipped by placing an empty comma (,) in the argument list, such as RANKX(Inventory, [InventoryCost],,,"Dense").

  • Equality related comparisons (=, <, >, >= and <=) between values with the Decimal Number data type can potentially return unexpected results when using RANKX function. Incorrect results can occur because values with Decimal Number data type are stored as IEEE Standard 754 floating point numbers and have inherent limitations in their precision. To avoid unexpected results, change the data type to Fixed Decimal Number or do a forced rounding using ROUND.

  • This function is not supported for use in DirectQuery mode when used in calculated columns or row-level security (RLS) rules.

Example

The following calculated column in the Products table calculates the sales ranking for each product in the Internet channel.

= RANKX(ALL(Products), SUMX(RELATEDTABLE(InternetSales), [SalesAmount]))

Other functions related to RANKX are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/rankx-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy