How do the INCLUDE function and FIXED function (LOD expression) work while adding a condition for both functions in Tableau? What is the difference between the INCLUDE function and the FIXED function in Tableau?
- Tableau FAQs
- December 11, 2018
INCLUDE – is used when you want to calculate a measure at a lower level of detail than the viz’s detail level. Your calculation will look at the dimensions on your view plus any additional dimensions you put in your statement.
{INCLUDE [City]: SUM([SalesYTD])}
{INCLUDE [City] – This is where you specify the level of detail
SUM([SalesYTD])} – Here, we indicate the measure to be calculated at this level.
In the example: We have countries on the X-axis, and in the bottom graph, we show SalesYTD. In the upper graph, along the same X-axis, we show AVG by LOD function with City detail. Thus, we can compare total sales and average sales for each city by country.
FIXED – function calculates your measure independent of what’s on your view. The Fixed function does not look at the view at all; it will calculate your measure depending on what dimensions you put in your equation and nothing else.
{FIXED [TerritoryGroup]: SUM([SalesYTD])}
{FIXED [TerritoryGroup]: – this is where you capture the level of detail of the data
SUM([SalesYTD])} – here you indicate the measure that will need to be calculated at a fixed level of data detail
You can also use both of these LOD functions in an IF statement. So, for example, you need to show a fixed value only to Europe, then you can use the following expression:
{FIXED [TerritoryGroup]:
SUM(
IF [TerritoryGroup]= "Europe"
THEN ([SalesYTD])
ELSE 0 END)}
{FIXED [TerritoryGroup]: – this is where you fix the level of detail
SUM( – then we need to specify the type of data aggregation, in our case, this is the sum of the result of the IF expression
IF [TerritoryGroup]= “Europe” – the expression evaluates to TRUE or FALSE
THEN ([SalesYTD]) – if the previous expression is TRUE, then we will need to output the SalesYTD field
ELSE 0 END)} – if the previous condition equals FALSE, then “0” will be included in the sum
{INCLUDE [City]:
SUM(
IF [City]= "Berlin"
THEN ([SalesYTD])
ELSE 0 END)}
{FIXED [City]: – this is where you fix the level of detail
SUM( – then we need to specify the type of data aggregation, in our case, this is the sum of the result of the IF expression
IF [City]= “Berlin” – the expression evaluates to TRUE or FALSE
THEN ([SalesYTD]) – if the previous expression is TRUE, then we will need to output the SalesYTD field
ELSE 0 END)} – if the previous condition equals FALSE, then “0” will be included in the sum
That is the difference between the INCLUDE and FIXED functions in Tableau.
Up Next:
Read How does Tableau recognize is not null in a calculated field in Tableau?