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()
| Parameter | Type | Description |
|---|---|---|
| None | N/A | INDEX() 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
1for the first row in a partitionIncrements by
1for each subsequent row
Example Output
| Row Position | INDEX() |
|---|---|
| 1st | 1 |
| 2nd | 2 |
| 3rd | 3 |
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() <= 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 calculationsINDEX()resets for each partitionNot 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.
It returns the sequential position of a row within a partition, starting at 1.
Yes, sorting directly determines the order and values returned by INDEX().
Yes, INDEX() is evaluated after aggregation and depends on the view layout.
Yes, it is commonly used to create Top-N or positional filters.
Yes, INDEX() restarts at 1 for every partition.