What is the IF Statement Tableau?
Tableau IF Statement is one of the logical functions available in Tableau that allows you to evaluate a condition as True or False and then perform operations based on the outcome. For example, classifying whether a person is overweight or underweight based on the BMI. Such functions help you to categorize or group the values based on conditions in Tableau.
For example, the below statement evaluates whether an order is profitable or not based on Sale Price and Manufacturing Price.
IF [Sale Price] > [Manufacturing Price] THEN “Profitable”
ELSEIF [Sale Price] = [Manufacturing Price] THEN “Break even”
ELSE “Loss”
END
Table of contents
Key Takeaways
Tableau IF Statement allows you to evaluate a condition as True or False and then perform assignments based on the outcome.
Syntax
The syntax of the IF statement in Tableau is provided below
IF <expr> THEN <then>
[ELSEIF <expr2> THEN <then2>…]
[ELSE <else>]
END

As you can see, the IF statement determines whether an expression is True or False, and based on the assessment, it executes the statement specified in THEN. If none of the conditions are evaluated to be true, it assigns the value specified in the ELSE statement.
How to use IF Statement in Tableau?
To use the IF Statement in Tableau, follow the instructions below:
Step 1: Connect your dataset to Tableau Desktop using the File Navigator
Step 2: Click on a New Worksheet in Tableau
Step 3: Drag and drop the Subcategory and Profit Margin fields to the Rows shelf and the Columns shelf respectively

Step 4: Right-click on the Data pane and select Create Calculated Field…

Step 5: In the calculation editor, specify the logic for the calculation and provide a meaningful name. Click on OK.

Step 6: Drag the Profitability field to the Tableau view and also to the Color in the Marks pane. Now your Tableau visualization is ready to use.

Note: To use Tableau if statement between two values, you can use the below syntax.
For example, the following IF statement checks whether a value falls between 0 to 100.
IF [Value] >= 0 AND [Value] <= 100 THEN ‘<then>’ ELSE ‘<else>’ END
Similarly, you can also use a Tableau if statement with string to evaluate an expression.
For example, IF [Category] = “Book” THEN “Reading” END
Examples
In this section, we will demonstrate different scenarios where you can use IF statements for your visualization requirements.
Example #1 – Nested IF Statements
In this example, we will demonstrate using nested if statements in Tableau, using Amazon_BooksDataset which contains essential information about each book, including metadata such as the title, author, price, reviews, and ratings focusing on the diverse range of books available on the platform.
To use the nested if statements in Tableau, follow the steps outlined below:
Step 1: Connect the Amazon_BooksDataset to the Tableau interface using the File Navigator. The imported data can be viewed in the Data Source tab.

Step 2: Navigate to a new worksheet. Select Analysis – Create Calculated Field…

Step 3: In the calculation editor, specify a meaningful name for the field. Provide the logic for the calculation using the nested if statements.
Here, we have created a field called Book Recommendation, which assigns the values based on Ratings by using Tableau if statement multiple conditions. Click on OK.

Tableau will create the calculated field, which is visible in the Data pane.

Step 4: Drag and drop the data fields to the Tableau view to create your visualization.
Here, we have dragged Category and Book Recommendation to the Rows shelf. Similarly, we have dragged the total count of books to the Columns shelf.

Example #2 – Tableau IF-ELSE Statement
In this example, we have created a Tableau visualization using if-else statements. To create this visualization, we have leveraged Walmart E-commerce Product Data in Tableau, which contains information such as product titles, URLs, brands, main images, SKUs, descriptions, GTIN-13 codes, models, etc., for Walmart’s e-commerce products.
To use the IF-ELSE statements in Tableau, follow the step-by-step guide provided below:
Step 1: Connect the Walmart E-commerce Product Data to the Tableau interface using File – Open.

Step 2: In the new worksheet, right-click on the Data pane and select Create Calculated Field…

Step 3: In the calculation editor, provide a name to the field and specify the conditional expression using an if-else statement to define the assignment.
Once the changes are completed, click on OK.

Tableau will create the calculated field.

Step 4: Now, create your data visualization in Tableau using the data fields, including the calculated field.
Here, we have dragged the Primary Category, Sub Category 1, Sub Category 2, and Brand to the Rows shelf, whereas the Price Category to the Columns shelf.

Step 5: Drag the Price Category to the Colors in the Marks pane.

Example #3 – Tableau ELSE-IF Statement
In this example, we have demonstrated another Tableau visualization using else-if statements. For this visualization, we have used the Supply Chain Management dataset. The Supply Chain Management dataset focuses on the supply chain management (SCM) practices of several prominent companies, capturing various metrics and performance indicators including SCM Practices, Supplier Count, Inventory Turnover Ratio, Lead Time (days), Order Fulfillment Rate (%), Customer Satisfaction (%), Environmental Impact Score and many more.
To create a data visualization using the else-if statements in Tableau, follow the instructions below:
Step 1: Connect the Supply Chain Management to the Tableau.

Step 2: Right-click on the Data pane and select Create Calculated Field.

Step 3: In the calculation editor, specify the name of the field and the logical expression to evaluate the value assignment. Click on OK post defining the logic.
Here, we have added Tableau if statement multiple conditions to assign a Supply Chain Score to the dataset based on many factors such as Inventory Turnover Ratio, Lead Time (days), Customer Satisfaction (%), Order fulfillment rate (%), etc.

Step 4: Create a visualization by dragging the data fields to the Tableau view. Drag the calculated field to the Colors in the Marks pane to assign colors.

Example #4 – Tableau IIF Function
In this example, we will create a visualization in Tableau using IIF functions. For this purpose, we have used Grocery Prices Data in Tableau. The Grocery Prices Data contains valuable insights capturing daily prices of grocery essentials such as Product Name, Category, Quantity, Original Price, Discount, Discounted Price, etc.
To use the IIF statements in Tableau, follow the instructions highlighted below:
Step 1: Connect the Grocery Prices Data to the Tableau desktop and import it into Tableau.

Step 2: Select Analysis – Create Calculated Field…

Step 3: In the Calculation editor, define the field name and logic to calculate the field value.
If you notice here IIF function is similar to the IF-ELSE statement.

It evaluates the test conditions and executes the then statement. The IIF statement here groups the data based on the discounts offered on different products.

Click on OK to save the changes.
Step 4: Drag and drop the data fields, including the calculated field, to the view.
Additionally, drag the calculated field to the Color in the Marks pane for your visualization.

Example #5 – Tableau IF Statement Using Aggregate Functions
In this example, we will demonstrate using IF statements in Tableau using aggregate functions. For this purpose, we have referenced the Online Sales Dataset – Popular Marketplace Data and used it in Tableau.
To use the nested if statements in Tableau, follow the steps outlined below:
Step 1: Connect the Online Sales Dataset – Popular Marketplace Data to the Tableau desktop.

Step 2: Navigate to Analysis – Create Calculated Fields…

Step 3: In the calculation editor, specify the conditions for the calculated field. Click on OK to save the changes.
Here, we have created a calculated field to calculate the revenue for Product Category Electronics and Home Appliances for North American regions that were paid via credit cards.

The calculated field is now visible in the Data pane.

Step 4: Drag the field to the Text in the Marks pane in the Tableau view.

Important Things to Note
- IF statement returns the value specified in THEN for the first evaluated expression that is True
- If no conditional expressions are evaluated as True then the default value is returned.
- You can use nested if statements for complex calculations and multiple expression evaluations. However, it is recommended to use other logical operators in this scenario, such as CASE or IN.
- Always ensure that the if statements you are using are defined as per syntax, data type compatible, and accurate in terms of logical expressions to result in expected output
- Avoid mixing Tableau IF statement aggregate and non-aggregate functions, as it will result in an error.
Frequently Asked Questions (FAQs)
To use Boolean in an if statement in Tableau, you can use conditional expressions.
For example, you can use expressions that evaluate True or False in IF statements.
The below IF statement uses Boolean output based on Profit Margin to assign a value.
IF([Profit Margin] > 0) THEN “Profitable”
ELSEIF [Profit Margin] = 0 THEN “Break even”
ELSE “Loss”
END
To use the count function in the IF statement in Tableau, follow the steps outlined below:
Step 1: Create a calculated field in the Data pane using the calculation editor.
Step 2: Specify the logic to use the count function as shown below.
IF SUM([Profit]) > 0 THEN COUNT([Order Id]) END
It will calculate the total customers who have contributed to profit in sales.
There can be various reasons why the Tableau IF statement is not working. Some of the key reasons and associated troubleshooting options include:
• Issues with syntax while writing IF statements can lead to incorrect syntax errors in Tableau. Refer to Tableau documentation to maintain the right syntax.
• Incorrect logical expressions can lead to unexpected results. Ensure that you specify correct logical expressions using IF statements and if possible, use the braces for correct indentation.
• Data type mismatches may also cause errors in Tableau. Consider the data type compatibility of the fields used in your IF statement.
• If you are mixing Tableau if statement aggregate and non-aggregate functions, then it will throw an error. Avoid mixing such functions while using the IF statement in Tableau.
IF statements can be beneficial if you have a simple or nested loop to define a conditional expression to evaluate. It evaluates an expression to a Boolean outcome, i.e., True or False, and then executes the assignment statement.
CASE statements are ideal when you have multiple conditional expressions to evaluate. Instead of using multiple nested conditional expressions or loops, you can evaluate the expression against multiple options. When a match is found, this returns the corresponding value; otherwise, a default value is returned. Hence, it is more structured and efficient than IF statements.
Download Template
This article must be helpful to understand the Tableau IF Statement, with its formula and examples. You can download the template here to use it instantly.
Recommended Articles
Guide to What is the Tableau IF Statement. We explain how to use IF Statement in tableau with syntax, examples, and downloadable template. You can learn more from the following articles –
Leave a Reply