Chapter 13. An Introduction to Table Calculations

Tableau comes with several preset calculations that you can compute with the numbers on a view, including running total, difference, percent difference, percent of total, moving average, and more. These predefined calculations are called table calculations because they compute the result based on a virtual table that includes only the numbers on the view. Table calculations provide several benefits, including:

  • A fast way to create advanced calculations even without knowing the underlying syntax

  • Table calculations can be saved for future use as calculated fields, and because calculated fields can be edited, this is a great way to learn the syntax and the different functions available in Tableau

  • Efficient processing—table calculations are computed on a very small subset of the data source, making them an efficient solution for calculating results

To help introduce table calculations and how to use them, we will be using this simple crosstab:

prta 1301

Table calculations are added to measures, so in order to add a table calculation, click a measure that’s on the view. The fastest way to add a table calculation is to hover over Quick Table Calculation and choose an option:

prta 1302

Here’s how the view looks after choosing the Running Total table calculation:

prta 1303

Table calculations are defined by how they are (a) partitioned (or grouped), and (b) addressed (or how they are computed). Notice in the example here the running total is being computed from left to right, which is the default addressing. This would mean that, by default, the table calculation is being addressed by the Product Category dimension. This leaves the Month dimension as the partitioning field. For a running total calculation, this doesn’t make a lot of sense. It is easy to change the addressing by changing how the table calculation is being computed. To do this, click the measure with the table calculation again, now identified with a delta symbol, hover over Compute Using, and change how the calculation should be computed (or addressed):

prta 1304

Here’s how the crosstab looks after changing the addressing/"Compute Using” to Table (down):

prta 1305

Now that the addressing field has been changed to Month and the partitioning field has been changed to Product Category, my result makes a lot more sense for my analysis. I can look at each Product Category column, and look down across months to see how the sales built up throughout the year.

There are many different options available within table calculations that can be accessed by clicking a measure with a table calculation and choosing “Edit table calculation.” For just a few possibilities, see one of Tableau’s most popular posts, Top 10 Tableau Table Calculations.

I mentioned in the introduction to this chapter that one of the benefits of table calculations is that they provide a way to learn the syntax. To do so, simply double-click a measure with a table calculation to see the underlying formula. This code can be copied into a calculated field so you can take a closer look.

Lastly, even though they are called table calculations, table calculations do not literally have to be used on a table, or crosstab, view. Here is one example I regularly use to add value to a basic monthly line graph:

prta 1306

Notice that the first row is a basic monthly trend, while the second Sales pill has a delta symbol, indicating there is a table calculation being applied. This time, I am using the second row to show the month-over-month difference in sales—another of the quick table calculation options available in Tableau.

To create this visualization, I started by simply making a line graph showing the sum of Sales by continuous Month of Order Date. I then placed a second occurrence of the Sales measure on the Rows Shelf, which created a second row with the exact same trend. Now that there were two independent pills for the Sales measure, I was able to add a table calculation for month-over-month difference (the second option under “Quick table calculation”) to the second pill only.

Each measure also gets its own set of Marks Cards, which means they can be edited independently. After changing the second row so the mark type is bar and the marks are colored by the month-over-month change, the result is the visualization just shown. Now in addition to a typical monthly sales trend, I’ve provided the month-over-month difference values and visualization, which allows the end user to quickly compare the spikes and drops across months; this value-add is made possible through Tableau table calculations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.5.49