Tableau – Logical Functions
Logical Functions are used to perform logical operations on the data in Tableau. It provides a variety of logical functions that can be used to test conditions, evaluate expressions, and perform calculations. Some of the commonly used Logical Functions in Tableau are as follows:
IF:
The IF function is used to test a series of expressions returning the <then> value for the first true <expr>.
Syntax:
IF <expr> THEN <then> [ELSEIF <expr2> THEN <then2> statement ] [ELSE <else>] ENDELSE:
The ELSE function is used to test a series of expressions returning the <then> value for the first true <expr>.
Syntax:
IF <expr> THEN <then> ELSE <else> ENDELSEIF:
The ELSEIF function is used to test a series of expressions returning the <then> value for the first true <expr>.
Syntax:
IF <expr> THEN <then> [ELSEIF <expr2> THEN <then2>...] [ELSE <else>] ENDCASE:
CASE performs logical tests and returns appropriate values. CASE evaluates an expression, compares it to a sequence of values, value1, value2, etc., and returns the result.
Syntax:
CASE <expression> WHEN <value1> THEN <return1> WHEN <value2> THEN <return2> ... ELSE <default return> ENDAND:
Logic conjunction is performed between two expressions using the AND function.
Syntax:
IF <expr1> AND <expr2> THEN <then> ENDOR:
Using the OR function, you can perform a disjunction operation between two expressions.
Syntax :
IF <expr1> OR <expr2> THEN <then> ENDNOT:
NOT is used to determine the logical negation of an expression.
Syntax:
IF NOT <expr> THEN <then> ENDTHEN:
The THEN function is used to test a series of expressions returning the <then> value for the first true <expr>.
Syntax:
IF <expre> THEN <then> [ELSEIF ,expr2> THEN <then2>...] [ELSE <else>] ENDWHEN:
The WHEN function is used to find the first <value> that matches <expr> and returns the corresponding <return>.
Syntax:
CASE <expr> WHEN <Value1> THEN <return1> ... [ELSE <else>] ENDEND:
The END function is used to test a series of expressions returning the <then> value for the first true <expr>. In an expression, it must be placed at the end.
Syntax:
IF <expr> THEN <then> [ELSEIF <expr2> THEN <then2>...] [ELSE <else>] ENDIn conclusion, Logical Functions in Tableau are powerful tools that can be used to manipulate and transform data in meaningful ways. By using these functions, you can perform complex calculations, create customized calculations, and gain deeper insights into your data.