Tableau If Function

In report design, Tableau If Function is one of the most useful decision-making functions. If function tests the condition, and depending upon the condition result, it will return the output.

In Tableau, we have three variants of if functions: If, If Else, ElseIf. In this article, we will show you how to use these three functions with examples.

For this Tableau If statement demonstration, we are going to use the data present in the Global Super Store Excel Worksheet so, Please refer Connecting to Excel Files in Tableau article to understand the connection settings.

Tableau If Function 1

Tableau If Statement Example

The Tableau If statement returns the result only if the given condition is True; otherwise, it returns nothing.

To demonstrate this Tableau If function, we need a Calculated Field. To create a calculated field, please navigate to Analysis Tab and select the Create Calculated Field… option, as shown below.

Tableau If Function 2

Once you click on the Create Calculated Field… option, the following window will be opened. Here, we renamed the default calculation name as If Exam. And the code is

IF(SUM([Profit]) > 0) THEN 'Performing Good'
END
Tableau If Function 3

Let me add this calculated field to the table (by dragging a field to Rows Shelf) that we created earlier. Please refer Create Table Report article to understand the steps involved in creating a table

Tableau If Function 4

From the above screenshot, you can see, it is returning NULL values for the failed condition. To avoid this NULLS, you have to use Tableau IF ELSE

Tableau If Else Function Example

The Tableau If Else function will test the condition.

  • If the test condition is true, the statement after the THEN keyword will return
  • If it is False, the statement after the Else keyword will return.

Tableau If Else Syntax

The syntax of the If Else in Tableau is as follows:

IF <Expression> THEN <True_statement>
ELSE <False_statement>
END

In this Tableau if else calculation, we are going to check whether the Profit is greater than 0 or not.

  • If the condition is TRUE then, Performing Good will be returned
  • If it is FALSE, Bad Performance will store in IfElse Exam field

Code that we used for this Tableau if else Statement is

IF(SUM([Profit]) > 0) THEN 'Performing Good'
ELSE 'Bad Performance'
END
Tableau If Function 5

Let me add this Tableau If Else calculated field to the table

Tableau If Function 6

Tableau ElseIf Function Example

The Tableau ElseIf function is handy to check multiple conditions. Remember, ELSE IF conditions will only execute if it’s previous IF or ELSEIF statement fails.

Tableau ElseIf Syntax

The syntax of the If Else in Tableau is as follows:

IF <Expression1> THEN <True_statement1>
ELSEIF <Expression2> THEN <True_statement2>
ESEIF <Expression3> THEN <True_statement3>
.....
ELSE <False_statement>
END

Tableau ElseIf function sequentially executes the statement. It will check the first condition,

  • If the condition is TRUE, it executes the statement after the THEN keyword.
  • If it is FALSE, it checks the Next one (ElseIf condition) and so on.

Code that we used for tableau else if below

IF(SUM([Profit]) > 6000000) THEN 'Profit'
    ELSEIF(SUM([Profit]) > 0) THEN 'Breakeven'
    ELSE 'Loss'
END
Tableau If Function 7

Let me add this Tableau If, if else and elseif Statement outputs to the existing table

Tableau If Function 8