The INDEX() function returns the index of the current row in the partition, without any sorting with regard to value. The first-row index starts at 1. For example, the table below shows quarterly sales. When INDEX() is computed within the Date partition, the index of each row is 1, 2, 3, 4…, etc. so let us go through an example in Tableau you so you can really see what this means.

Note: I use the INDEX() function in pretty much every worksheet I build.

Worksheet

We are going to be a worksheet that will allow us to see the INDEX() function in action.

Note: There are quite a few fun data sets there so do have a look around. You can also find some nice data sets on Google Dataset search: https://toolbox.google.com/datasetsearch

  • Start Tableau Desktop / Public
  • Open the world_cup_results.xlsx
  • Drag the World Cup – Tableau Format onto the data pane
  • Click on Sheet1
    • Drag Team onto Rows
    • Drag Date onto Columns
    • Create a new Calculated Field called Index with the formula: INDEX()
    • Drag Number of Records onto Text
    • Make sure you are looking at a table and observe the results

In a basic sense, you can see the number of records for each team for each world cup year. This is pretty simple stuff, but now let us drag the Index Calculated Field onto Text and see what happens. Now the whole table should be full of numbers which indicates the position depending on how it is calculated.

  • Right click on Index, go to Compute Using and see that Table (across) is selected
  • Select Table (down) and observe the results
  • Check out the other options and observe the difference:
    • Table (across then down)
    • Table (down then across)
    • Cell
    • Date
    • Team

My common usages for the INDEX() function includes:

  • Top N Filters – More often than not I use Index to filter for the top or bottom N records
  • Sorting – Sometimes I use this function for custom sorting
  • Densification and Drawing – You can see this in a lot of my drawing tutorials

You can read more about the INDEX() function here:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.