Tableau RANK() Function

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:

FunctionDescription
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.

  1. 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.
Show Top N results in tableau chart
  1. 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
  1. Now, drag State to Rows and Sales to Columns.
Use calculated field to show Top N records in Tableau
  1. Drag the calculated field to the Filters. Then, in the Filter, select the Show checkbox and click OK.
Display top N results in Tableau chart using Rank
  1. To dynamically change the top “N” numbers, click on the parameter Top N and select Show Parameter.
Tableau Chart Show Top N results
  1. 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.
Show top N results using rank in Tableau

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.

  1. To create the chart view, add the Region to Rows and Sales to Columns.
  1. Now, create a calculated field named Region Rank Modified using the formula below.
RANK_MODIFIED(SUM([Sales]), 'desc')
  1. Drag this calculated field to the Text card in the Marks section.
Rank Modified in Tableau

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.

  1. To create the view, add the Product to the Rows and Sales or Price to the Text card in the Marks section.
  1. 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.

  1. Add the calculated field to the Text card. After this, click the calculated field in the text and select Table down.
Tableau Rank Unique function

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

Show Ranking in Tableau

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:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.