Components of calculation in Tableau?

Tableau Calculation

There are four necessary components to the calculation in Tableau:

  1. Function: Function statements are used to transform the values or members in a field.
    For Example: The format of all functions in Tableau such as SUM (expression).
  2. Fields: Field is dimensions and measures from your data source.
    For Example: A field in a calculation is often surrounded by brackets such as [Sales].
  3. Operators: Operator is a symbol that denotes an operation between the operands.
    For Example: The types of operators you can use in Tableau calculations, as well as the order they are performed in a formula such as +, -, *, /, %, ==, =, >, <, >=, <=, ! =, <>, ^, AND, OR, NOT, ( )
  4. Literal Expression: Literals expression are represent the constant values “as is” such as “profitable” and “unprofitable”.
    For Example: See the below calculation

IF [Profit per Day] > 5000THEN"Highly Profitable"
ELSEIF [Profit per Day] <= 0THEN"Unprofitable"
ELSE “Profitable”
END

The component of the above calculation can be further divided into the following:

  1. Functions: IF, THEN, ELSEIF, ELSE, and END.
  2. Field: Profit per Day.
  3. Operators: > and <=.
  4. Literal Expression
  • String Literals: “Highly Profitable”, “Unprofitable”, and “Profitable”.
  • Numeric Literals: 5000, and 0.

Note: Not all calculation needs to contain all the four components.

Here is some important point for literal expression syntax:

  • Numeric literals are written as numbers.
    Example: 27 or 1.3567
  • String literals are written with quotation marks.
    Example: “profitable.”
  • Date literals are written with the # symbol.
    Example: # June 8, 2018 #
  • Boolean literals are written as either true or false.
    Example: “True” or “False”
  • Null literals are written as null.
    Example: “NULL”

Two more calculations contain by Tableau

  1. Parameters: Parameter is a placeholder variable that can be inserted into calculations to replace the constant values.
    A parameter in a calculation is surrounded by brackets .
    For Example: [Profit Bin Size]
  2. Comments: Comment is defined as the notes about a calculation or its parts, but comments not included in the computation of the calculation.
    To enter a comment in a calculation, use two forward slashes //.
    For Example

SUM ([Sales]) / SUM ([Profit]) // Nick’s calculation
// to be used for profit ratio
// Do not edit