Monday, January 28, 2013

Custom Calculations in Tableau

Today, we'll look at custom calculations in Tableau.  In my opinion, these are the most useful tools in Tableau's arsenal.  They can be used to calculate almost any value you would need, and can even be used in some clever ways to spice up your charts.  As usual, we will use the Superstore Sales sample data set in Tableau.

Step 1:
  • Decide what value you want
Step 2:
  • Select "Analysis -> Create Calculated Field..."
Here, you can peruse the list of functions in the bottom-right corner to see what kind of calculations you can create.  These calculations follow a simple rule, they are always calculated with respect to the cell they are in.  For instance, if your graph displays Profit by State, then SUM( [Profit] ) will be calculated for each state.  Let's create this field.

Step 3:
  • Type "SUM( [Profit] )" into the Formula box.
  • Type "Sum of Profit" into the Name box.
Step 4:
  • Find the new Calculated Field in the Measures Pane.
  • Create a Worksheet with this Field.
Profit by Sub-Category
You might be saying "Hey, we already had a Sum of Profit field by dragging Profit onto the chart!"  You're right, the default aggregation for Profit is Sum; so, dragging it onto the chart will give you exactly these values.  Now, let's get a little more complex (and useful) and create a new field that we don't have access to already.

Step 5:
  • Create a Calculated Field named "Profit per Item"
  • In the formula box, type "SUM( [Profit] ) / SUM( [Order Quantity] )"
  • Add this Field to your Worksheet
Profit and Profit Per Item by Sub-Category
Now that you know how to create Calculated Fields, you can explore a whole new world inside Tableau.  Thanks for reading.

Brad Llewellyn
Associate Consultant
Mariner, LLC

No comments:

Post a Comment