Smarter Visuals with Logic: A Tableau Starter Guide
Smart Visuals Start with Logic: A Beginner’s Guide to IF Statements in Tableau
When I started learning Tableau, I thought the magic was all in the charts. But soon I realized that behind every smart visualization is logic. And the real hero? The humble IF statement. I wanted to not just create dashboards that look good, but also ones that think smart. That’s where logical functions like IF, IF...ELSE and CASE came in.
In this post, I’ll share how I use these functions as a beginner and how they helped me build more insightful dashboards.
Logical Function:
Tableau provides various Logical Functions to perform logical operations on our data. They are Tableau AND, NOT, OR, IF, ELSEIF, IF Else, CASE, ISNULL, IFNULL, IIF, etc.
Let’s discuss every logical function one by one with an example.
Using the AND Function in Tableau:
The AND function is used when two or more conditions must be true at the same time.
If both conditions are True, it returns True. Otherwise, it returns False.
Syntax:
IF condition1 AND condition2 THEN result END
Example:
IF [Age] > 50 AND [Glucose Level] > 180 THEN "High Risk" ELSE "Normal" END
This means: If a patient is over 50 and has a glucose level above 180, label them as "High Risk". Otherwise, label as "Normal".
OR Function:
The OR function in Tableau lets you test multiple conditions, and if at least one of them is true, the result will be true.OR function is like an either-or statement in English. If both conditions are False, Tableau or will return False; otherwise, it returns True.
Syntax:
IF condition1 OR condition2 THEN result ELSE other_result END
Example:
IF [Smoker] = "Yes" OR [Alcohol Use] = "Yes" THEN "Risk of HTN" ELSE "Low Risk" END
This means:
If someone smokes or uses alcohol, they’re labeled "Risk of Hypertension".If neither condition is true, they’re labeled "Low Risk".
IIF Function:
The Tableau IIF function is the simple version of the If Else Function. If both conditions are True, then it’ll return the First Statement; otherwise, the second statement. Great for quick labels or basic logic in calculated fields
Syntax:
IIF(condition, value_if_true, value_if_false)
Example:
IIF([BMI] > 30, "Obese", "Normal")
This means: If BMI is over 30 → return “Obese” ,Otherwise → return “Normal”
NOT Function:
The Tableau NOT function returns the exact opposite. I mean, True will become false and vice versa.
Syntax:
NOT(Expression)
Example:
IF NOT [Smoker] = "Yes" THEN "Non-Smoker" ELSE "Smoker" END
This means:
If the person is not a smoker, label them "Non-Smoker."Otherwise, label them "Smoker"
ISNULL Function:
The Tableau ISNULL function will check whether it is NULL or Not. If it’s NULL, then it returns TRUE; otherwise, False will returns. Helps identify missing data, Great for cleaning datasets.
Syntax: ISNULL(expression)
Example:
IF ISNULL([Patient ID]) THEN "Missing Info" ELSE "Valid Entry" END
This means:
If a record doesn’t have a Patient ID, it’s marked as "Missing Info",If the ID is present, it’s marked "Valid Entry"
IFNULL Function:
The IFNULL function is used to replace null (blank) values with a default value of your choice. Replacing missing numbers with 0 or "N/A", Avoiding blank values in charts and calculations, Creating clean, user-friendly dashboards, we use IFNULL.
Syntax:
IFNULL(expression, replacement_value)
Example:
IFNULL([Glucose Level], 0)
This means:If the Glucose value is missing, show 0 instead If it’s available, show the actual value.
IF Function:
In Tableau If Function is one of the foremost useful decision-making functions. If the function tests the condition and depending upon the condition result, it’ll return the output.
Syntax:
IF condition THEN result_if_true ELSE result_if_false END
You can skip ELSE if you only want something to happen when the condition is true. Always end with END.
Example:
1.IF [Age] > 60 THEN "Senior" ELSE "Adult" END
This means:
If a patient's age is above 60, label them “Senior”, Otherwise, label them “Adult”
IF - ELSEIF - ELSE – END:
You can nest multiple IF statements or use ELSEIF like this:
Syntax:
IF condition1 THEN result1
ELSEIF condition2 THEN result2
ELSE result3
END
Example:
IF [Age] < 18 THEN "Child"
ELSEIF [Age] >= 18 AND [Age] < 60 THEN "Adult"
ELSE "Senior"
END
This assigns a category based on age:
Under 18 → "Child", 18–59 → "Adult", 60 and above → "Senior"
Why Use It?
For clean, readable categorization
Great for dashboards that group data
Easier than nesting many IF statements
Case Function:
The Case Function is a part of the Logical functions in Tableau. These functions are used to perform the logical test and return the required value when the test expression is true.
Syntax:
CASE expression
WHEN value1 THEN result1
WHEN value2 THEN result2
...
ELSE default_result
END
Example:
CASE [Diagnosis Code]
WHEN "D1" THEN "Diabetes"
WHEN "H1" THEN "Hypertension"
WHEN "K1" THEN "Kidney Diseases"
ELSE "Other"
END
This will:
Return "Diabetes" if the code is D1
Return "Hypertension" if the code is H1
Return "Kidney Diseases" if it’s K1
Return "Other" for any other code
When to Use CASE:
When comparing one field to many values
For cleaner, more readable logic than multiple IF/ELSEIF statements
To label or group categories in dashboards
Logical functions make your data smart. Without them, Tableau is just a pretty chart maker — with them, it's a powerful decision-making tool.


