Tableau Funtion: INDEX( )

Tableau Function: INDEX( )

Category: Table Calculation Functions

Purpose

The INDEX() function in Tableau is a table calculation that returns the sequential position of a row (or mark) within a partition. It assigns an incremental number to each row based on the current sort order and computation scope.

In simple terms, INDEX() answers the question:
“What number is this row in the current view?”

Type of Calculations

  • Table calculations

  • Sequential indexing

  • Order-dependent calculations

  • Position-based logic

INDEX() is evaluated after aggregation and is fully dependent on how data is displayed in the view.

Practical Use Cases

  • Creating custom row numbers

  • Implementing Top-N or Bottom-N logic

  • Building rank-like calculations

  • Creating running totals or offsets

  • Controlling visibility of rows in dashboards


INDEX()

ParameterTypeDescription
NoneN/AINDEX() has no parameters. Its output depends on partitioning, sorting, and table calculation direction.

How It Works?

Logical Principle

INDEX() assigns a 1-based sequential number to each row within a partition:

INDEX() = Row Position (starting at 1)

The value of INDEX() depends on:

  • Sort order

  • Partitioning (Compute Using)

  • Direction of calculation (Table Down, Table Across, Pane Down, etc.)

If any of these change, the resulting index values change as well.

Example Formula

INDEX() <= 10

Keeps only the first 10 rows in the current partition

What Does It Return?

  • Data Type: Integer

  • Meaning:

    • Returns 1 for the first row in a partition

    • Increments by 1 for each subsequent row

Example Output

Row PositionINDEX()
1st1
2nd2
3rd3

When Should We Use It?

Use INDEX() when you need to:

  • Number rows dynamically in a view

  • Filter records based on position

  • Create Top-N or Bottom-N filters

  • Build running or cumulative calculations

  • Control logic based on row order

Basic Usage

Create a row number


INDEX()

  • Displays a sequential number for each row
  • Useful for tabular views and reports

Column Usage

Filter to show only the first 5 rows


INDEX() &lt;= 5

  • Commonly used for Top-N dashboards
  • Works based on current sort order

Advanced Usage

Running total using INDEX()


IF INDEX() = 1 THEN SUM([Sales])
ELSE PREVIOUS_VALUE(0) + SUM([Sales])
END

  • Creates a custom running total
  • Demonstrates advanced table calculation logic

Tips and Tricks

  • Always define sorting before using INDEX()

  • Check Compute Using to ensure correct partitioning

  • Combine with LOOKUP() for offset-based calculations

  • INDEX() resets for each partition

  • Not suitable for row-level or LOD calculations

Related Functions You Might Need

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

  • FIRST()

  • LAST()

  • LOOKUP()

  • RANK()

  • RANK_DENSE()

  • RUNNING_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 INDEX() do in Tableau?

It returns the sequential position of a row within a partition, starting at 1.

2. Is INDEX() affected by sorting?

Yes, sorting directly determines the order and values returned by INDEX().

3. Is INDEX() a table calculation?

Yes, INDEX() is evaluated after aggregation and depends on the view layout.

4. Can INDEX() be used to filter data?

Yes, it is commonly used to create Top-N or positional filters.

5. Does INDEX() reset for each partition?

Yes, INDEX() restarts at 1 for every partition.