Calculated Fields in Tableau

Calculated fields enables users to create fields in the data source and these fields will operate just as any other field from the original source.   Some common functionality that calculations can be used for include: Segmenting data, converting data types, aggregating data, filtering results and calculating new metrics.  

There are 3 main types of calculated fields in Tableau.  First are the Basic Calculation, which are used to solve most regular calculation use cases like aggregation, filtering and so on.  They are similar to the way calculations are done in Excel.  The second type are Level of Detail expressions or LODs. These calculations support aggregation at dimensionality other than the view level meaning at a level that is not presented in the sheet.  The last type of calculations are the Table Calculations.  These are calculations that are applied to the values within a view and computed in Tableau rather than in the data source.

The Calculation Syntax. Syntax represents how calculations are structured in Tableau.  There are 7 distinct parts of calculation, but not all of them may be used all together in every calculation.  Comments are notes used for documentation or providing additional context, which are commented out in two back slashes. Logical expressions determine if a certain condition is true or false (boolean), or used to evaluate sequences of values (if, then statements).   Parameters are dynamic driving fields that can materially impact calculations and filters. Operators are numeric and logical symbols used in calculations like =, >,<,-,+, *, /, ==, !=, AND, OR, NOT, () to mention some. Literal expressions are constant values which can be represented as numbers, strings, dates and more.   These are hard coded values in the calculation that wont change dynamically but can be used as reference points. Fields or the columns in the dataset, are raw or calculated columns which are used for dimensional or aggregated values. Functions drives the action in calculation like numerical, string, type, date, logical , aggregate , user table calculation, or spatial functions.  There will be different structure for every type of calculation but all have these fundamental features.

Calculated fields can be created in several ways: through the Analysis menu, through the drop down arrow beside view data button, in the data pane or direct in column or row shelves.  These calculations are temporary and not stored in the workbook or data source, but can be materialized by drag and drop in the view.

Aggregation is the process of combining or summarizing data into a single representative value. Both Dimension and Measures can be aggregated in different ways. Aggregation level is controlled by the dimension in the view and the type of calculation being used.

There three main types of Aggregation in Tableau, namely: row-level, dynamic aggregation and user-defined level detail of calculation.  Row-level Aggregation is performed at the lowest level or grain of the data and this has no defined aggregation in the calculated field. This calculation will aggregate after the calculation is performed and dragged into the view.  Dynamic aggregation is aggregated at the level of detail in the view.  When an aggregation is applied inside a field an AGG abbreviation will display in the pill. User-defined aggregation are aggregated at the level of detail explicitly defined in the LOD expression.  This type of calculation will ignore the level detail of the view and only perform the calculation defined level of detail in the calculation.

Aggregation Mix Errors.  Errors in aggregation are common when creating calculation.  When using both aggregated and non-aggregated fields in the same calculation, it will result to an error. Calculations must always be in the same level in the calculated field, for example when one measure is aggregated, the other must be aggregated too.

Author:
Kristine Wiesner
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