How to Add Index in Tableau

Cody Schneider7 min read

Adding a simple row number or rank to a table in Tableau seems like it should be easy, but it often stumps new users. The key is understanding one of Tableau’s most useful table calculation functions: INDEX(). This article walks you through exactly what the INDEX() function does, how to use it step-by-step, and how to configure it correctly for different scenarios.

What Exactly is the INDEX() Function in Tableau?

In simple terms, the INDEX() function returns the position, or row number, of the current row within a partition. Think of it as a counter that adds a sequential number (1, 2, 3...) to a list of data in your view. Because it's a table calculation, its output depends on how your table is arranged and how you tell Tableau to "compute" the index.

This simple function is surprisingly powerful and serves as the foundation for many common tasks in Tableau, including:

  • Creating ranked lists (e.g., Top 10 products by sales).
  • Assigning a unique ID to each row in your visualization.
  • Filtering your view to show specific rankings, like only the top 5 results.
  • Building more advanced charts where the position of a mark is important.

The secret to mastering INDEX() isn't just knowing the function itself, but understanding how to control its calculation using the "Compute Using" setting. We'll get to that in a moment.

How to Add a Basic Index: A Step-by-Step Guide

Let's start with the most common scenario: adding a rank or row number to a sorted list of items. We'll use the "Sample - Superstore" dataset that comes with Tableau.

Our goal is to create a simple table that lists all product Sub-Categories sorted by total sales, with a rank number next to each one.

Step 1: Set Up Your Initial Visualization

First, create the basic view you want to add row numbers to.

  1. Connect to the Sample - Superstore data source.
  2. Drag the Sub-Category dimension to the Rows shelf.
  3. Drag the Sales measure to the Columns shelf.
  4. Click the Sort Descending icon in the toolbar. This ensures your highest-selling sub-categories are at the top.
  5. You should now have a simple bar chart showing sales by sub-category, from highest to lowest.

Your view should look something like this, with "Phones" and "Chairs" at the top.

Step 2: Create the INDEX() Calculated Field

Now, we need to create the calculation that will generate our row numbers.

  1. In the Data pane on the left, right-click and select Create Calculated Field.
  2. Name your calculation something clear, like "Rank_Index" or simply "Index".
  3. In the formula box, type the function:
INDEX()

That's it! The formula is just the function itself. Click OK.

Step 3: Add the Index to Your View

With the calculated field created, you can now add it to your table to see the row numbers.

  1. Find your new "Rank_Index" field in the Data pane.
  2. Drag it to the Rows shelf and place it just to the right of the "Sub-Category" pill.
  3. Tableau will likely treat it as a continuous measure and try to create an axis. We'll fix that next.

Step 4: Convert the Index to Discrete

To make the index appear as a tidy row number instead of a continuous axis, you need to change its property to "Discrete." A discrete field creates labels, while a continuous field creates an axis.

  1. On the Rows shelf, right-click the green "Rank_Index" pill.
  2. Select Discrete from the context menu.

The pill will turn blue, and you'll now see a neat column of numbers from 1 to 17, perfectly aligned with your sorted sub-categories. "Phones" will have the number 1, "Chairs" will have 2, and so on. Success! You've just added a rank to your view.

Controlling Your Index with "Compute Using"

The simple example above works because Tableau's default calculation setting - "Table (Down)" - was correct for our needs. It calculated the index number by going down the list one row at a time. But what if you have a more complex view with groupings?

This is where "Compute Using" comes in. This setting tells Tableau the direction and scope of a table calculation. Let's see it in action.

Scenario: Ranking Sub-Categories Within Each Category

Imagine your manager asks to see the top-selling sub-categories ranked within each main product category. They don’t want a single rank from 1-17, they want the index to restart at 1 for "Furniture," then restart again at 1 for "Office Supplies," and again for "Technology."

  1. Modify the View: Drag the Category dimension to the Rows shelf and place it to the left of "Sub-Category." Your view now has groupings.
  2. Observe the Problem: Notice how the "Rank_Index" column keeps counting sequentially. Your number ranking for "Bookcases" (under Furniture) might be 4, and "Storage" (under Office Supplies) might be 5. The index isn't restarting for each new category.
  3. Fix it with "Compute Using": We need to change how the index is calculated.

Instantly, your view updates. The "Rank_Index" now restarts at 1 for each new pane (i.e., for each Category). "Chairs" will be Rank 1 within "Furniture," "Binders" will be Rank 1 within "Office Supplies," and "Phones" will be Rank 1 within "Technology." This subtle change completely transforms the meaning of your calculation and gives you the exact insight you need.

The "Compute Using" setting lets you define the partition (what groups the calculation) and the addressing (what sets the order). By selecting "Pane (Down)," we told Tableau to partition the calculation by "Category" and address it by "Sub-Category" sales.

Practical Applications of a Tableau Index

Now that you know how to create and control an index, let's explore a few powerful ways to apply it.

1. Create a "Top N" Filter

One of the most common uses for INDEX() is to filter your view to show only the top performers, like the top 10 products or top 5 sales reps.

  1. Start with the simple ranked list we created in the first example (Sub-Category by Sales, with the "Rank_Index" field).
  2. Drag your "Rank_Index" calculated field from the pane (or the shelf) onto the Filters shelf.
  3. A dialog box will appear asking how you want to filter. You can select a range of values. Set the range to be from 1 to 10.
  4. Click OK. Your view will immediately be filtered to show only the top 10 sub-categories.

Pro Tip: You can make this filter dynamic by pairing it with a parameter. Create a parameter called "Top N," then change your filter on "Rank_Index" to be [Rank_Index] <= [Top N Parameter]. This allows users to choose how many top items they want to see directly on the dashboard.

2. Format Every Nth Row

Sometimes in large tables, you may want to add visual banding to make the data easier to read. You can use INDEX() along with the Modulo operator (%) to identify every 3rd, 5th, or Nth row.

Create a T/F calculated field named "Is Fifth Row":

INDEX() % 5 = 0

This calculation returns "True" for every 5th row (5, 10, 15, etc.). Drag this new field onto the Color Marks Card. Rows where the calculation is true will get one color, and all other rows will get another, creating a visually striped table.

3. Provide Stable Row Identifiers

Unlike a database ID, which is tied to the data itself, INDEX() is tied to the visualization's structure. This means it provides a stable row number as it appears on the screen. If a user resorts the table, the index will correctly re-calculate from 1 downward in the new order. This is incredibly useful for when you need a clear, visible row identifier that always reflects the current sort order and structure of your table.

Final Thoughts

The INDEX() function in Tableau is a simple but essential tool for adding ranks, row identifiers, and building powerful filters. Once you master how to set its Compute Using property correctly, you unlock the ability to control exactly how it behaves in nested tables and other complex visualizations, giving you precise control over your analysis.

Manually creating calculations, configuring partitions, and filtering data in tools like Tableau offers amazing control but also comes with a learning curve. That’s why we built Graphed. Instead of spending hours wrangling table calculations, you can connect your marketing and sales data and just ask a question in plain English, like "Show me a dashboard of my top 10 products by revenue last quarter," and get a live, interactive dashboard built for you instantly.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.