Making Tableau Think: A Guide to Logical Calculations

Choosing the right chart is only half the job. The other half is telling Tableau what to do with your data.

This is where logical calculations come in.

What is a logical calculation?

A logical calculation evaluates whether something is TRUE or FALSE and then uses that result to determine what happens next with our data.

Think of them as telling Tableau: "If this is true, do this. Otherwise, do that.”

And once you start using them, they become incredibly useful.

IF statements:

The IF statement is probably one of the most familiar logical calculations. The syntax follows:

Plain text
IF <condition> THEN <result>
ELSE <alternative result>
END

For example,

Plain text
IF [Profit] > 0 THEN "Profitable"
ELSE "Loss"
END

This is essentially asking Tableau, "Is Profit greater than 0?"

If the answer is yes, then return profitable or else, loss .

THEN and ELSE statements:

THEN and ELSE statements comes hand in hand with the IF statements.

  • The THEN statement tells Tableau what to return when the condition is TRUE.
  • And the ELSE statement tells us what to return when the condition is FALSE.

In this example,

Plain text
IF [Profit] > 0 THEN "Profitable"
ELSE "Loss"
END

[Profit] > 0 is the condition, while "Profitable" is the result returned when that condition is met (TRUE). The ELSE statement tells Tableau what to return when the condition is FALSE.

ELSEIF Statements:

But what if we want more than two outcomes? This is where ELSEIF comes in.

For example, we could split profit into three categories:

Plain text
IF [Profit] > 1000 THEN "High Profit"
ELSEIF [Profit] > 0 THEN "Profit"
ELSE "Loss"
END

Here, Tableau checks the conditions from top to bottom.

  • If profit is greater than 1,000 → High Profit
  • Otherwise, if profit is greater than 0 → Profit
  • If neither condition is met → Loss

So, in simple terms:

IF → What are we checking first?
THEN → What should happen if it's true?
ELSEIF → Is there another condition to check?
ELSE → What should happen if none of the conditions are true?
END → The calculation is finished.

IIF: A shorter IF statement

If you only need to choose between two outcomes, Tableau also has IIF.

IIF stands for Immediate IF and is essentially a shorter way of writing an IF/ELSE statement.

For example:

Plain text
IIF([Profit] > 0, "Profitable", "Loss")

This asks the same question as the earlier example: “Is Profit greater than 0?”

If the answer is TRUE, Tableau returns "Profitable". If the answer is FALSE, it returns "Loss".

Compare this with the longer version, both produce the same result. The main difference is the way they are written.

IIF follows a simple structure:

Plain text
IIF(<condition>, <value if TRUE>, <value if FALSE>)

So, if we only have one condition and two possible outcomes, IIF can be a quick and compact alternative to IF...ELSE.

CASE and WHEN Statements:

So far, we’ve used IF, ELSEIF and ELSE to build conditions and decide what Tableau should return. But sometimes, we’re not really asking a question, we simply want to check a field against a list of possible values.

This is where CASE comes in.

CASE is useful when you want to compare one field against multiple fields or values and return a different result for each match.

And the WHEN statement is used to specify the value Tableau should look for.

For example, if we want to group different regions into larger areas:

Plain text
CASE [Region]
    WHEN "East" THEN "Group 1"
    WHEN "West" THEN "Group 1"
    WHEN "Central" THEN "Group 2"
    WHEN "South" THEN "Group 2"
END

Here, Tableau looks at the value in [Region] and checks which WHEN condition it matches.

  • If [Region] is "East" → return "Group 1"
  • If [Region] is "West" → return "Group 1"
  • If [Region] is "Central" → return "Group 2"
  • If [Region] is "South" → return "Group 2"

So, while an IF statement is useful for checking conditions, CASE is often cleaner when you're checking one field against several specific values.

To put it simply:

CASE → Tells Tableau which field to check
WHEN → Specifies a value to look for
THEN → Specifies what to return if it matches
ELSE Specified what to return if it doesn't match

Checking and handling your data


Logical calculations aren't only about creating categories. Tableau also has functions that help you check your data and handle missing values.

ISDATE

ISDATE checks whether a value can be recognised as a date. It returns either TRUE or FALSE.

For example:

ISDATE([Order Date])

If [Order Date] contains a valid date, Tableau returns TRUE. Otherwise, it returns FALSE. This can be useful when checking whether a field contains values in the format you expect.

ISNULL

ISNULL checks whether a value is NULL, meaning that the value is missing.

Plain text
ISNULL([Profit])

If [Profit] is missing, Tableau returns TRUE. If it contains a value, it returns FALSE.

We can also combine it with IF:

Plain text
IF ISNULL([Profit]) THEN "Missing"
ELSE "Available"
END

This allows us to identify missing values directly in our visualisation.

IFNULL

While ISNULL tells us whether a value is missing, IFNULL lets us replace it.

Plain text
IFNULL([Profit], 0)

This means, if [Profit] is NULL, return 0. Otherwise, return the original [Profit] value.

ZN

ZN is another way to deal with NULL values, specifically by replacing them with zero.

Plain text
ZN([Profit])

If [Profit] is NULL, Tableau returns 0. If it already has a value, that value stays unchanged.

So why use IFNULL instead of ZN?

The key difference is that IFNULL lets us choose what to replace NULL with, while ZN specifically replaces NULL with zero.

These functions are particularly useful when working with real-world data, where missing values are common and can affect calculations and visualisations.

Logical calculations might seem small, but they can make a big difference in how we understand and present your data.

Author:
Rahim Afsana
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2026 The Information Lab