0% found this document useful (0 votes)
4 views

Building_Logical_Statements

Uploaded by

shailenderojha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Building_Logical_Statements

Uploaded by

shailenderojha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

BUILDING LOGICAL STATEMENTS

These are sometimes called Logical statements or Logical expressions


or Logical functions.

Logical calculations allow us to determine if a certain condition is true


or false (Boolean logic).

For example, you might want to quickly see if profit for each region is
above or below a certain threshold.

The logical calculation might look something like this:

SUM(Profit) > 5000


BUILDING LOGICAL STATEMENTS
There are many Logical functions available in Tableau, but we will be going through
only 2 functions
IF THEN ELSEIF
CASE

Syntax for IF THEN ELSEIF statement:

IF <expr> THEN <then>


[ELSEIF <expr2>
THEN <then2>...]
[ELSE <else>]
END

Description of IF, THEN & ELSEIF Function:

Tests a series of expressions returning the <then> value for the first true <expr>.
If there is no true <exp> including ELSE, then Null is returned.
BUILDING LOGICAL STATEMENTS

Syntax for CASE statement:

CASE <expression>
WHEN <value1> THEN <return1>
WHEN <value2> THEN <return2> ...
ELSE <default return>
END
BUILDING LOGICAL STATEMENTS
Description of CASE Function:

Performs logical tests and returns appropriate values.


The CASE function evaluates expression, compares it to a sequence of values,
value1, value2, etc., and returns a result.
When a value that matches expression is encountered, CASE returns the
corresponding return value.
If no match is found, the default return expression is used.
If there is no default return and no values match, then Null is returned.

CASE is often easier to use than IIF or IF THEN ELSE.

Typically, an IF function can be used to perform a sequence of arbitrary tests, and a


CASE function can be used to search for a match to an expression.
But a CASE function can always be rewritten as an IF function , although the CASE
function will generally be more concise.
STEPS TO CREATE IF THEN ELSEIF CALCULATION

Step 1: Select Analysis > Create Calculated Field


STEPS TO CREATE IF THEN ELSEIF CALCULATION

Step 2: Calculation Editor will open


STEPS TO CREATE IF THEN ELSEIF CALCULATION

Step 3: Name the calculated field, IF THEN ELSEIF Cond.


Enter the below mentioned formula
Confirm that a "The calculation is valid" message is seen
When finished, Click OK
STEPS TO CREATE IF THEN ELSEIF CALCULATION

Step 4: The new calculated field appears under Measures in the Data pane.
Just like other fields, we can use it in one or more visualizations.
STEPS TO CREATE IF THEN ELSEIF CALCULATION
Step 5: To confirm if the calculated condition is working correctly create the
below mentioned Viz
Rows Shelf: Sub-Category, IF THEN ELSEIF Cond (New Calculated Field)
Label of Marks Card: Profit
Color of Marks Card: IF THEN ELSEIF Cond (New Calculated Field)
Sort descending by SUM of Profit
STEPS TO CREATE CASE CALCULATION

Step 1: Select Analysis > Create Calculated Field


STEPS TO CREATE CASE CALCULATION

Step 2: Calculation Editor will open


STEPS TO CREATE CASE CALCULATION
Step 3: Name the calculated field, CASE Statement.
Enter the below mentioned formula
Confirm that a "The calculation is valid" message is seen
When finished, Click OK
STEPS TO CREATE CASE CALCULATION
Step 4: The new calculated field appears under Measures in the Data pane.
Move the field to Dimensions section since we need to use it along
with Categorical data e.g.: Sub-Category
STEPS TO CREATE CASE CALCULATION
Step 5: To confirm if the calculated condition is working correctly create the
below mentioned Viz
Rows Shelf: Sub-Category
Label of Marks Card: Case Statement (New Calculated Field)

You might also like