Tableau Funtion: RANK( )

Tableau Function: RANK( )

Category: Table Calculation Functions

Purpose

The RANK() function in Tableau is a table calculation that assigns a ranking value to each row (or mark) within a partition based on a specified numeric expression. The rank reflects the relative position of each value when the data is sorted.

In simple terms, RANK() answers:
“How does this value compare to others in the current view?”

Type of Calculations

  • Table calculations

  • Order-based ranking

  • Relative comparison calculations

  • Post-aggregation analytics

RANK() is evaluated after aggregation and is fully dependent on the view’s sort order and partitioning.

Practical Use Cases

  • Creating Top-N or Bottom-N analyses

  • Ranking products, customers, or regions by performance

  • Building leaderboard-style dashboards

  • Applying conditional formatting based on rank

  • Filtering data dynamically by rank


RANK(expression, [order])

ParameterTypeDescription
expressionAggregate / table calculationThe numeric value to rank. Must be aggregated in the view.
order (optional)Scalar (string)Specifies sort direction: "asc" for ascending or "desc" for descending. Default is "desc".

How It Works?

Logical Principle

RANK() sorts values within a partition and assigns ranks based on their position:

RANK(value) = position in sorted order

Key behaviors:

  • Default sort order is descending

  • Ties receive the same rank

  • Subsequent ranks are skipped (standard competition ranking)

What Does It Return?

  • Data Type: Integer

  • Meaning:

    • Returns 1 for the highest-ranked value (by default)

    • Tied values receive the same rank, and the next rank is skipped

Example Output

ValueRANK()
5001
4002
4002
3004

When Should We Use It?

Use RANK() when you need to:

  • Compare performance across categories

  • Identify top or bottom performers

  • Create ranked visualizations or tables

  • Apply rank-based filtering or labeling

  • Build competitive or benchmark-style dashboards

Basic Usage

Rank values in descending order


RANK(SUM([Sales]))

  • Highest sales receive rank 1

Column Usage

Rank in ascending order


RANK(SUM([Profit]), "asc")

Lowest profit receives rank 1

Filter Top 10 values


RANK(SUM([Sales])) <= 10

Shows only the top 10 records

Advanced Usage

Conditional formatting based on rank


IF RANK(SUM([Sales])) <= 3 THEN "Top 3"
ELSE "Others"
END

Highlights top performers

Rank within partitions


RANK(SUM([Sales]))

(with Compute Using set per region)

Produces rankings independently within each region

Tips and Tricks

  • Always confirm sorting and Compute Using

  • Use RANK_DENSE() if you don’t want skipped ranks

  • Combine with parameters for dynamic Top-N filters

  • Rankings change if sort order changes

  • Not suitable for row-level calculations

Related Functions You Might Need

Functions commonly used alongside or as alternatives to RANK():

  • RANK_DENSE()

  • RANK_UNIQUE()

  • INDEX()

  • FIRST()

  • LAST()

  • WINDOW_SUM()

We’ve got plenty of resources to help you master Tableau functions. For more details, check out the official Tableau documentation. Or, if you’re ready for more practice, let’s dive into related functions and build your Tableau skills further!

If you’re ready to harness the full power of Tableau and elevate your data analytics capabilities, our expert Tableau consulting services are here to guide you. Whether you need support with building advanced calculated fields, creating dynamic visual dashboards, or optimizing your data sources for peak performance, our team of experienced Tableau consultants delivers customized solutions designed for your business needs. Visit our Tableau Consulting page to discover how we can help your organization turn data into impactful, insight-driven decisions.

1. What does RANK() do in Tableau?

It assigns a ranking value to rows based on a numeric expression and sort order.

2. How does RANK() handle ties?

Tied values receive the same rank, and the next rank is skipped.

3. What is the default sort order for RANK()?

Descending order (highest value ranked first).

4. Is RANK() a table calculation?

Yes, it is evaluated after aggregation and depends on the view layout.

5. How is RANK() different from RANK_DENSE()?

RANK() skips ranks after ties, while RANK_DENSE() does not.