Wednesday, February 27, 2013

Working with Table Calculations in Tableau

Today, we will look at basic Table Calculations in Tableau.  Table calculations are the computational workhorse of Tableau.  They allow you to calculate values outside of the traditional realm of "Slice by X Dimension."  Tableau has a few built-in table calculations, we will use the "Running Sum."  We will also look at the Index() function and how to properly use the "Compute Using" property.  As usual, we will use the Superstore Sales sample data set in Tableau.

Step 1:
  • Create a table with a dimension and a measure
Sales by Container
Step 2:
  • Right-Click [Sales] in the "Text" Shelf -> "Quick Table Calculation" -> "Running Sum"
  • Add [Sales] to the graph again to be sure the Running Sum is working as it should.
Running Sum of Sales by Container
Now, you can see that the Running Sum is the sum of all Sales in preceding categories.  This is extremely handy in quite a few places.  Now, let's look into the Index() function and the Compute Using property.

Step 1: 
  • Create an empty table with two dimensions
Blank by Order Priority and Category
Step 2:
  • Create the following calculated field:
Index
By default, Table Calculations typically use the Compute Using setting of "Table (Across)", which means it runs across the graph.  See the following pictures:

Blank by Order Priority and Category (Column Index)
Blank by Order Priority and Category (Row Index)
Just like the name implies, it runs across the table.  However, we can force it to run other directions or even across a specific variable.

Step 3:
  • Add [Sub-Category] to the Rows Shelf
  • Right-Click [Index] from the Measures Shelf -> "Edit"
  • Click the blue text "Default Table Calculation"
  • Choose "Compute Using" -> Sub-Category
  • Add [Index] to the Rows Shelf
Blank by Category, Sub-Category, and Order Priority (Row Index on Sub-Category)
Now, you can see that the Index runs along Sub-Category with no regard to the fact that Order Priority is also there.  Mastering Compute Using is essential to mastering Tableau.  Try using more complicated indexes, or maybe some more of the default table calcuations.  I hope you found this informative.  Thanks for reading.

Brad Llewellyn
Associate Consultant
Mariner, LLC
llewellyn.wb@gmail.com
https://www.linkedin.com/in/bradllewellyn

4 comments:

  1. I don't seem to have Sub-Category in my Superstore example. Tableau Desktop 8.

    ReplyDelete
    Replies
    1. The Tableau 8 version doesn't seem to have sub-category. It's no biggie, you can replace it with any dimension you want.

      Delete
    2. Thanks, Brad. I figured as much, but I wanted to make sure I wasn't missing something I was supposed to have. Enjoying your blog. Very informative. Thanks for publishing it.

      Delete