01 / 20

Conditional Logic
in Tableau Calculations

Master IF, ELSEIF, and CASE statements to build dynamic, intelligent calculated fields in Tableau.

Tableau

What Is Conditional Logic?

Conditional logic allows your calculations to make decisions. Instead of applying the same formula to every row of data, you can branch into different outcomes based on whether a condition is true or false.

Why It Matters in Tableau

Categorize
Group rows into buckets like "High", "Medium", and "Low" based on a measure.
Flag
Mark records that meet a threshold: overdue orders, top customers, at-risk accounts.
Transform
Apply different formulas to different segments: discount rates, tax rules, scoring models.

The Three Conditional Tools

Tableau provides three primary constructs for branching logic in calculated fields:

1
IF / ELSEIF / ELSE: evaluate one or more Boolean conditions in sequence and return the result of the first match.
2
IIF: a compact, single-condition inline function that returns one of two values.
3
CASE: compare a single expression against a list of discrete values and return the matching result.

The IF Statement: Syntax

IF <condition> THEN <result_1> ELSEIF <condition_2> THEN <result_2> ELSE <default_result> END

How IF Evaluates

Start Condition 1 TRUE? YES Result 1 NO Condition 2 TRUE? YES Result 2 NO ELSE Default

The CASE Statement: Syntax

CASE <expression> WHEN "value_1" THEN <result_1> WHEN "value_2" THEN <result_2> ELSE <default_result> END

IF vs CASE: Key Distinction

IF / ELSEIF CASE
Evaluates Boolean expressions Single expression vs values
Condition type Any: \( > \), \( < \), \( = \), AND, OR Equality only (\( = \))
Best for Ranges, complex rules Discrete categories
Readability Can get verbose Clean with many values
ELSE clause Optional Optional

The IIF Shortcut

IIF(<condition>, <true_result>, <false_result>)

IIF is a compact, single-condition function. It takes exactly three arguments: a Boolean test, the value if TRUE, and the value if FALSE. There is no ELSEIF: for multiple branches, use IF instead.

How to Apply Conditional Logic

1
Identify the question. What decision does the calculation need to make? Categorize, flag, or transform?
2
Choose the construct. Equality checks → CASE. Ranges or complex logic → IF. Simple binary → IIF.
3
Order conditions carefully. In IF/ELSEIF, place the most restrictive condition first so it does not get overshadowed.
4
Always include ELSE. Handle unexpected values gracefully to avoid NULLs in your view.
5
Test with edge cases. Check NULLs, zero values, and boundary conditions.

Example 1: Profit Tier

Classify each order as High, Medium, or Low profit:

IF [Profit] > 200 THEN "High" ELSEIF [Profit] > 50 THEN "Medium" ELSE "Low" END

Example 2: Region Mapping

Map region abbreviations to full names using CASE:

CASE [Region] WHEN "NE" THEN "Northeast" WHEN "SE" THEN "Southeast" WHEN "MW" THEN "Midwest" WHEN "W" THEN "West" ELSE "Unknown" END

Example 3: Dynamic Discount

Apply a discount rate that depends on both customer segment and order amount:

IF [Segment] = "Corporate" AND [Sales] > 5000 THEN [Sales] * 0.15 ELSEIF [Segment] = "Corporate" THEN [Sales] * 0.10 ELSEIF [Sales] > 5000 THEN [Sales] * 0.08 ELSE [Sales] * 0.05 END

Nesting vs Chaining

Nested IF
An IF inside another IF's THEN or ELSE branch. Powerful but quickly becomes hard to read and debug.
ELSEIF Chain
A flat sequence of ELSEIF clauses. Easier to read, maintain, and extend. Preferred in almost every situation.

Common Mistakes

✕ Wrong Condition Order
Placing a broad condition before a specific one. IF \(\text{Sales} > 100\) fires before IF \(\text{Sales} > 500\) can ever be reached.
✕ Missing ELSE
Omitting the ELSE clause produces NULL for any unmatched row, which can break aggregations and filters.
✕ CASE with Ranges
Trying \(\text{WHEN} > 100\) inside CASE. CASE only checks equality. Use IF for inequality comparisons.

Summary Comparison

IF / ELSEIF IIF CASE
Branches Unlimited 2 (true/false) Unlimited
Condition Any Boolean Any Boolean Equality only
Ranges ✓ Yes ✓ Yes ✕ No
Readability Good Best (short) Best (many values)
Use case Complex rules Binary flags Dimension mapping

Question 1 of 5

Which statement is TRUE about the CASE construct in Tableau?

Question 2 of 5

A record with \(\text{Sales} = 750\) would be classified as:

Question 3 of 5

You need to create a calculated field that maps four product categories to custom display names. Which construct is most readable?

Question 4 of 5

What happens when an IF/ELSEIF statement has no ELSE clause and none of the conditions are TRUE?

Question 5 of 5

Which function is best for creating a simple binary flag like "In Stock" vs "Out of Stock"?