Tableau If Function

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

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

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

Table report 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.

Create a Calculated Field 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'
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 Statement 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 If ELSE

Tableau If Else Function Example

The If Else function will test the condition.

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

Tableau If Else Statement Syntax

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

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

In this Tableau if else function contains calculation, we are going to check the statement 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 the IfElse Exam field

Code that we used for this Tableau if else Statement contains is

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

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

Tableau If Else Function statement 6

Tableau ElseIf Function Example

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

The syntax of the ElseIf is as follows:

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

The 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 this else if below

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

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

Tableau else If Function Statement 8