Introduction To Calculated Fields: Custom & Table Calculations

Calculated fields can be formed from custom calculations, using the calculated field editor with your data source. Calculations can be formed as an aggregated calculation or non-aggregated (row-level). Calculated fields are particularly useful when your data source does not contain all the values you need for your analysis.

Calculated Fields can include:

  • Fields - Contains all the data source fields and calculated fields
  • Functions - Use to create a formula, which is available from the dropdown-menu (Number, String, Date, Type Conversion, Logical, Aggregate, User, Table Calculation, Spatial)
Field names from data pane come up as orange text in the formula editor
  • Operators - Standard Operations; Addition (+), subtraction (-), multiplication (*), modulo (%), division (/); Comparisions (E.g. ==,=,>,<,>=,<=,!=,<>); and logical (E.g. AND, OR, NOT, IF)

An example using a logical operator using IF statement:
If we wanted to find out (when aggregated) how many products reached sales over 100,000

For an introduction to IF statments read this blog by the Flerlage Twins A Beginner’s Guide to IF Statements in Tableau

Therefore 10 products are above the threshold, while 7 are below

Using a similar example we can see how this would look when non-aggregaed (row-level):
How many sales within each product are above 1000?

To switch from aggregated to non-aggregated in this example, I removed the SUM() around the sales field
Looking at the first bar in the chart we decipher that 115,066 records were above the threshold while 214,941 were below the threshold 
  • Parameters - Placeholder variables that can be inserted into calculations to replace constant values
    For more information about parameters read this blog by Tanya Fischer Creating an easy Parameter in Tableau
  • Comments - Type two forward slash characters (//) into the formula pane to annotate your calculations, the editor will go back to normal on the next line
  • Syntax error: when creating a custom calculated field it's very important that your syntax is correct or your calculated field will not work - by hovering bottom left corner Tableau explains why there is a syntax error

Custom Calculated fields are very versatile and allow you to gain more control of your data, especially when you create Level of Detain expressions (LOD) in the formula editor, which allows you to specify the granularity for an aggregation.
Adam Ratcliffe wrote an introduction to LODs - Level of Detail Calculations - The Basics


Another way calculated fields can be generated is through table calculation within Tableau (calculations applied after the data is returned). Some predefined table calculations are available as quick table calculations, but you can also specify the components of the formula.
See Andy Krebel's blog explains Table Calculations - Table Calculations Overview

For each category and sub-category, compute the percent of total, by the Year (Order Date)

Calculated fields can be a little scary at first, but with practice and familiarity it's a very useful skill to have to help with your analysis.

Author:
Valerie Madojemu
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab