Tableau Advanced Table Calculations Guide
Tableau Advanced Table Calculations Guide
Table Calculations Hands-On session at TCC 2013. In addition to the steps, comments have been
added in various spots to explain the why and how of what is occurring.
The sheets referenced here are the exact same names as the sheets in both the Instructions and
Solutions workbooks. Lets get started:
Create a calculated field called Average Sales with the following formula:
Create a calculated field called YoY Average with the following formula:
Takeaway:
The purpose of this exercise is two-fold. First, it is crucial to understand that table calculations
cannot always be written in one formula. Often times the structure of the visualization forces us
to break calculations into their underlying pieces. In this case, we have to run two calcs in two
different directions to get our desired results.
Second, it is important to understand that a table calculation that relies on one or more table
calculationsYoY Average relies on Average Salesmust be set carefully. Had you right
clicked YoY Average, hovered over compute using and selected Table Across, you would have
seen results different than what you wanted. One must always ensure that all underlying table
calculations are being computed correctly before worrying about the final calculation.
2. Retention
Right click Retention Percentage in the Measures pane, hover over default properties and
select Number Format. Select Percentage and click OK
Add the calculation to rows shelf. This should result in the final viz looking like this:
Takeaway:
The purpose of this exercise is to demonstrate the usefulness of offsets in window calculations.
These offsets can be used in any number of ways to achieve any number of calculations. They
are especially powerful when you have dynamic ranges of data like this case. Here we want to
get the number of customers that exist between the current and last rows of the table (inclusive)
at each point in the table. This is not, unfortunately, a static range. Using offsets with our
window_sum here allows us to dynamically calculate our results within the specified range for
each mark.
This compute using allows us now to get percent of totals for each region. In other words,
because of the fields we added to addressing, the marks in each region now add up to 100%.
This view solves our problem and answers our questions but it is a terrible view. It is not clear
what any of the information demonstrated means.
Create a calculated field called Order Timing with the following formula:
This calculation demonstrates a powerful new feature of Tableau 8.0: using sets in calculated
fields. This will give us a clean, easy way to present our information to our users. Since Sets are
just Boolean fields, stating something like IF [First after 2010] THEN is equivalent to IF [First
after 2010]=True THEN.
Takeaway
There are several reasons why this exercise was included. First, it demonstrates that table
calculations can be used against In/Out sets (another feature new to Tableau 8). Second, it
demonstrates that table calculations are not limited to just
4. Lookup on Dimension
Create a calculated field called % Diff from Department with the following formula:
Takeaway
The purpose of this exercise is to expose a bit of functionality that is often overlooked by users.
Omitting an offset with lookup allows you to achieve some powerful point in time analysis. In
the above example, we have allowed our users to dynamically choose the relative to value but
this isnt required. If you want to always compare your sales to a specific start year, lookup with
a static relative to value will allow you to do this.
This view is the first step in our case study of blending and table calculations. Please continue to
the next sheet.
Right click this field in the Measures pane, hover over default properties and select
Number Format. Change this to a percentage and hit OK
Double click Est % of Income to bring it into the view
You should now have something that looks like the following for Alabama:
Create a calculated field called Average % of Income with the following formula:
Takeaway
Table calcs are powerful tools when a single data source is in play. They are, however, just as
powerful when blending is involved. Table calculations can allow us to combine disparate data
for our analysis needs in simple and interesting ways. Here, we have taken a simple calculation
from one datasource, created a new calculation in the primary data source and then used a table
calculation to achieve our final end analysis. This case study is meant to demonstrate that
disparate data issuesdue to different levels of granularities in this casecan be approached
thoughtfully and effectively with table calculations in many situations.
Right click you 6. Weighted Average Income (Step 2) tab and click Duplicate Sheet
Remove Sales, Weighted Average Income and Est % of Income from the Measure Values
shelf
Click Show Me and choose Filled Map (the upper rightmost option)
Move Customer to the Detail shelf
Add Average % of Income to the label shelf as well (ctrl click drag a copy to the label
shelf)
You should now see the following:
Our map now shows us the correct numbers we want. It is not, however, our final visualization.
If you look in the bottom left corner of your Tableau Desktop, you will see that we have 2703
marks. This is due to Customer being on level of detail. For every customer in every state, we get
a mark.
Add this field to the Detail shelf, right click it, hover over compute using and select
Customer Name
Add this field to the Filters shelf and keep the True values.
Notice in the bottom left that we now only have 49 marks1 for each state.
Finally, right click Customer Name and uncheck Include in Tooltip by clicking the option
Takeaway
This is an example of how table calculations are not limited to tabular style crosstabs or bar
charts. Our compute using settings from Step 2 are still valid here as Customer Names are still
partitioned into groups by the State field.
Furthermore, the index()=1 calculation is a powerful table calculation. It allows us to hide marks
that we do not care to see. In this case, we hid all of the duplicate marks within each state.
Similar calculations include last()=0, first()=0 or index()=n where n is the nth mark you want to
either hide or keep.
Right click your Weighted Average Income (Step 3) tab and click Duplicate Sheet
Click Show Me and click the crosstab option
Move Customer Name to the right of State
Add Region to the left of State
Right click your Filter field on the Filters shelf and click Edit Table Calculation
Click the compute using dropdown and select advanced
Add State and Customer name to the Addressing section (in that order) and click OK
twice
Select True again and hit OK
Move Average % of Income to the Columns shelf
Right click State and uncheck Include in Tooltip by clicking the option
Right click both State and Customer Name and uncheck Show Header
Right click anywhere in the view, click format, select the borders option and move the
Row Divider to the first level to remove the extra lines displayed in the graph. The final
result should look like the following:
Takeaway
The purpose of this exercise was to demonstrate the flexibility of table calculations in the context
of blending disparate data. Not only did we aggregate customer level results to the State level but
we also further aggregated this to a regional level. Table calculations can extend your analyses in
flexible and dynamic manners when blending is required.