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 largest.
- ‘desc’ ranks from largest to smallest (this is the default).
You’ll usually use RANK() as a calculated field, then add it to your view as a table calculation.
When should you use RANK()?
I usually reach for RANK() whenever I need to:
- Highlight top N or bottom N performers (top 10 customers, top 5 products, worst 3 regions).
- Compare performance across categories (how a product ranks inside its category or region).
- Add context to charts (for example, ranking bars in a bar chart instead of just showing raw numbers).
- Build leaderboard-style dashboards (sales reps, teams, stores, etc.).
Think of RANK() as the “leaderboard builder” in Tableau.
Types of RANK() Function in Tableau
In Tableau, there are several ranking functions to handle the ranking of dimensions and measures differently:
| Function | Description |
|---|---|
| RANK() | Gives the same rank to identical values and skips the next rank. (e.g., 1, 2, 2, 4) |
| RANK_DENSE() | Gives the same rank to identical values but doesn’t skip the next rank. (e.g., 1, 2, 2, 3) |
| RANK_MODIFIED() | Averages the ranks of identical values. (e.g., if two values tie for 2nd, both get 3 in ascending order) |
| RANK_UNIQUE() | Assigns a unique rank to each record, even if values are identical. |
Use the RANK function in Tableau
In the examples below, we will see how the RANK() function in Tableau is used in different scenarios.
Example-1: Use the Rank Function to Show Top N Results
In this example, we will create a calculated field using the RANK function to display the top N records in the Tableau chart. In this chart, we will display sales by top states using the Superstore dataset.
- Right-click in the Data Pane -> Create Parameter and add the following details.
- Name: Top N.
- Data Type: Integer.
- Current Value: 10.
- Select Range, and add the minimum and maximum values of the range.
- Click OK.

- Create a calculated field named Index Filter and enter the formula below. This formula will filter the top n results using RANK.
IF RANK(SUM([Sales])) <= [Top N] THEN
"Show"
ELSE
"Hide"
END- Now, drag State to Rows and Sales to Columns.

- Drag the calculated field to the Filters. Then, in the Filter, select the Show checkbox and click OK.

- To dynamically change the top “N” numbers, click on the parameter Top N and select Show Parameter.

- Now, we can see the “Top N” parameter on the right side of the chart, from which we can dynamically change the “N” value to display the top “N” results.

As we change the parameter digit, the same number of top results will be displayed in the Tableau chart.
This way, we can show the top N results in Tableau using the RANK function in Tableau.
Example-2: Use RANK_Modified() for Regional Sales Ranking
In this example, we will use the Rank_DENSE() function to categorise regions into tiers (e.g., Top 3-performing regions) where sales values should not skip ranks. For example, if two Regions have the same sales, then they will have the same sales ranking.
In my dataset, I have two records with the same sales value. Using the RANK_Modified, we will assign a ranking to these records. Here, records having similar values will be assigned the same ranks.
- To create the chart view, add the Region to Rows and Sales to Columns.
- Now, create a calculated field named Region Rank Modified using the formula below.
RANK_MODIFIED(SUM([Sales]), 'desc')- Drag this calculated field to the Text card in the Marks section.

In the ranking of the records, we can see that duplicate ranks share the same number, and the next rank increases sequentially, with no gaps before or after.
Example-3: Use RANK UNIQUE to Give Rank to Each Value
The RANK_UNIQUE function returns the unique rank for the current row in the partition, assigning different ranks to identical values.
For example, with this function, the set of values (4,10,15,15,20) would be ranked (5,4,3,2,1) in descending order.
The same set of values (4, 10, 15, 15, 20) would be ranked (1, 2, 3, 4, 5) in ascending order.
- To create the view, add the Product to the Rows and Sales or Price to the Text card in the Marks section.
- Create a calculated field to rank the records with unique values in descending order.
RANK_UNIQUE(SUM([Price]), 'desc')This formula assigns unique ranks even when two records have equal values.
- Add the calculated field to the Text card. After this, click the calculated field in the text and select Table down.

Now, we can see that for the equal values, the ranking is also assigned with unique values.

This way, we can assign ranks in Tableau using the Rank_Unique method.
In all the above methods, the rank will be computed in descending order when order is not defined in the syntax.
Conclusion
In this Tableau tutorial, we learned how to assign rankings to data in Tableau using different RANK functions. We have also learned how each function behaves differently when there are duplicate values.
Here, the RANK() skips ranks for ties, RANK_DENSE() gives the same rank without skipping, RANK_MODIFIED() adjusts ranks sequentially, and RANK_UNIQUE() assigns unique ranks even to identical values.
By using the RANK function in calculated fields and parameters, we can easily create dynamic charts, such as top-N reports and regional performance rankings.
You may also like to read:
- Tableau LOOKUP() Function
- ATTR() Function in Tableau
- Calculate Percentage of Total in Tableau
- Repeat Row Labels in Tableau
- CASE Statement in Tableau
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.