Video | Tableau | Data visualisation | Analytics

The main logical functions in Tableau

A video covering the basics of getting started with logical functions in Tableau.

Part ofTableau Functions
Watch on YouTube
  • Treat an IF statement as asking Tableau a question: IF condition THEN result ELSE result END, and remember string values must be wrapped in speech marks to match your data exactly.
  • Use ELSEIF to chain multiple conditions, but always close the chain with a single ELSE; you can nest entire calculations or further IFs after any THEN.
  • AND requires both conditions to be true, OR only one; at row level an AND check must reference different fields, since one row can't hold two genres simultaneously.
  • IFNULL([field], 0) is a shorthand that replaces nulls with a value, doing the same job as IF ISNULL or ZN but far more concisely.
  • IIF(test, true-result, false-result) writes a single-condition IF/ELSE in three comma-separated parts, a quick hack when you only need one check.

Setting up the dataset

Tableau sheet showing genre and country hierarchy with revenue field and null values visible

Logical functions are probably the most fundamental thing you can pick up when learning Tableau, so this walkthrough breaks down IF, THEN, ELSE, ELSEIF, AND and OR, plus a couple of handy shortcuts.

To set things up I connected to a mock dataset (linked in the description so you can follow along) built around film genres and the rough revenue they generate in each country. The values aren’t realistic, it’s purely a sample.

Dragging genre onto rows with country in front gives a clean hierarchy and shows the structure of the data. Notice the genre field uses a pipe separator where more than one film type sits in the same genre, and the revenue field contains some null values, entries that weren’t put into the database. They aren’t nothing and they aren’t zero, they’re simply null.

Writing your first IF statement

Completed IF statement: IF genre = "action" THEN NULL ELSE revenue END with valid calculation indicator

The best way to think about an IF expression is as asking a question of Tableau. As a plain-English comment: IF genre equals action, then make it null, otherwise keep the value.

Two things matter when writing the condition. Genre is a string field, so the value you check against has to match exactly, and a string literal must be wrapped in speech marks. Typing action on its own won’t work; it has to be "action".

The full calculation reads IF [genre] = "action" THEN NULL ELSE [revenue] END. Use [revenue], not SUM([revenue]), because this is a basic row-level calculation. Tableau is fairly permissive about casing and you can write it in sentence case, but the logic stays the same: if the genre is action, return null, otherwise return the existing value.

Call it new revenue, apply, and drag it straight into the view, you don’t need to close the calculation window. Action now shows as null. Change the condition to "action|comedy" and the values update dynamically, proving the statement is working.

Chaining conditions with ELSEIF

Multiple ELSEIF chain checking action, action|comedy, action|adventure, and drama genres with null results

Once you want to ask more than one question, ELSEIF comes in. After your first condition you can put ELSEIF on a new line and ask the next question, then another, and so on.

The key rule: you must always finish the chain with a single ELSE, not another ELSEIF. You can keep adding ELSEIF lines as long as you like, but the final fallback is always one ELSE.

I’ve opened workbooks with fifty ELSEIF statements in a row because someone had fifty values in a dimension, often used to clean up misspelled categories. That works, but anything after a THEN can be a whole calculation, an LOD, or even a nested IF, so the logic can get complicated fast. My advice is to solve that kind of thing in a data prep tool where you can, and only reach for nested logic here when this is the only tool you’ve got.

Using AND and OR statements

OR statement calculation with genre conditions formatted on separate lines for readability

The more natural way to ask multiple questions is with AND and OR, because that’s how we talk: I’d love to see this and this, or I wouldn’t mind seeing this or that.

OR checks whether one condition or another is true. Crucially, Tableau isn’t smart enough to let you write genre = "action" OR "action|adventure". You have to repeat the whole question: IF [genre] = "action" OR [genre] = "action|adventure" OR [genre] = "drama" THEN NULL ELSE [revenue] END.

Formatting each condition on its own line makes the calculation far easier for the next person to read and edit, they can see exactly which sections to change.

AND pitfalls at row level

AND statement checking genre equals action AND country equals France, returning null for France row

AN OR statement only needs one condition to be true to fire. Swap OR for AND and every condition must be true simultaneously, and that’s where people trip up.

At row level a single row can’t hold two genres at once, so an AND check across the same field will never match. If you want AND, you have to check different fields or conditions. For example, IF [genre] = "action" AND [country] = "France" THEN NULL ELSE [revenue] END works because genre and country are different columns that can both be true on the same row.

So: OR lets you check items within the same dimension as well as conditions across multiple dimensions, while AND won’t let you check the same thing twice on a single row.

The IFNULL shorthand

IFNULL(revenue, 0) calculation alongside the longer IF ISNULL equivalent in the editor

If all you’re doing is checking for a missing value, IFNULL is a fast shortcut. IFNULL([revenue], 0) checks the first expression, and if it’s null returns the second value, here zero.

The long-hand equivalent would be IF ISNULL([revenue]) THEN 0 ELSE [revenue] END, which does exactly the same job but takes far more typing. It also does the same thing as the ZN function for handling nulls, so there are three ways to write the same check, IFNULL being the neatest.

The IIF function

IIF calculation: IIF(genre = "action", NULL, revenue) shown in the calculation window

The double-IF, IIF, is a super-speedy way to write a single-condition IF/ELSE in three comma-separated parts: the test, the true result, and the false result. IIF([genre] = "action", NULL, [revenue]).

Instead of THEN you use a comma, and the ELSE result follows the next comma. You can’t run multiple checks with it, but when you only need one condition it’s the faster, cleaner option that saves you writing out a full IF statement.

Why these functions matter

These are functions you’ll use constantly. I probably reach for IF two or three times a day inside Tableau workbooks, whether fixing quick problems, building filters, or creating conditional colouring.

If you don’t know how to use IF logic you’ll struggle with Tableau, it’s a core foundational function everyone needs. If this is the first thing you learn and you understand it, you’re going to do well.

I’ve kept these examples in tables rather than building visualisations, because adding that complexity would stretch each video out enormously, and there are plenty of fully built-out examples elsewhere. This is the place to be if you just want the fundamentals.