0
0
Tableaubi_tool~5 mins

Logical functions (IF, IIF, CASE) in Tableau - Step-by-Step Guide

Choose your learning style9 modes available
Introduction
Logical functions in Tableau help you make decisions in your data. They let you check conditions and show different results based on those checks. This is useful when you want to categorize data or create new fields based on rules.
When you want to label sales as 'High' or 'Low' based on a threshold.
When you need to assign regions to sales reps based on their location codes.
When you want to create a new field that shows 'Yes' if a customer bought more than 5 items, otherwise 'No'.
When you want to group products into categories using multiple conditions.
When you want to replace missing or null values with a default value.
Steps
Step 1: Click
- Analysis menu > Create Calculated Field
A dialog box opens to create a new calculated field
💡 Name your calculated field clearly, like 'Sales Category'
Step 2: Type
- Calculation editor
You enter the logical formula using IF, IIF, or CASE
💡 Start with IF for simple conditions, IIF for short true/false, CASE for multiple choices
Step 3: Click
- OK button in the calculation editor
The new calculated field appears in the Data pane under Dimensions or Measures
Step 4: Drag
- New calculated field to Rows or Columns shelf or to Marks card
The visualization updates to show data grouped or filtered by your logical condition
Before vs After
Before
Data shows raw sales numbers without categories
After
Data shows sales categorized as 'High' or 'Low' based on sales amount
Settings Reference
Calculation editor
📍 Analysis menu > Create Calculated Field
Write logical expressions to create new fields based on conditions
Default: Empty editor
Common Mistakes
Forgetting to close IF statements with END
Tableau requires END to finish IF blocks, otherwise calculation errors occur
Always add END after the IF...THEN...ELSE parts
Using IIF for multiple conditions
IIF only handles one true/false check, not multiple cases
Use IF or CASE for multiple conditions
Not handling NULL values in logical expressions
NULL can cause unexpected results or errors
Use ISNULL() or include ELSE clauses to handle NULLs
Summary
Logical functions let you create new fields based on conditions in Tableau.
Use IF for flexible conditions, IIF for simple true/false, and CASE for multiple choices.
Always close IF statements with END and handle NULL values carefully.