Tableau’s RANK() function lets you sort your data and assign positions to each row, so you can quickly answer questions like “Who are my top 10 customers?” or “Which region is performing worst?”
Sorting the data was helpful, but I wanted to automatically assign ranks to each region based on its sales values. In solution, I learned that it can be done using the Tableau RANK() function.
This function allows us to assign a position or ranking to each data point based on a measure such as Sales, Profit, or any calculated field.
In this Tableau tutorial, I’ll explain the Tableau RANK() function, with the different rank types we can use, and how to apply it for data visualisation.
What is the RANK() function in Tableau?
In Tableau, RANK() is a table calculation that assigns a position (1, 2, 3, …) to each row in a partition based on a measure.
In simple terms:
- You pick a number to sort by (for example, Sales).
- Tableau orders rows using that number.
- RANK() assigns each row a rank based on that order.
The basic syntax is:
RANK(aggregate_expression, ['asc' | 'desc'])
Where:
- aggregate_expression is usually something like SUM([Sales]), AVG([Profit]), etc.
- ‘asc’ ranks from smallest to larges