# The main logical functions in Tableau

> This is content from just-tim, the data-and-analytics channel by Tim Ngwena (formerly 'Tableau Tim'). Tim has 12+ years of hands-on BI experience and covers Tableau most of all, plus Power BI, Looker, Hex, SQL and data modelling, the analytics industry, and the craft of doing the job — always tool-agnostic and honest about the trade-offs.

- **Author:** Tim Ngwena (just-tim, https://just-tim.com/about)
- **Published:** 2021-02-10
- **Format:** Video · 1633 min watch · transcript available
- **Topics:** Data visualisation, Analytics
- **Tools:** Tableau (calculated fields, ifnull, iif)
- **Canonical:** https://just-tim.com/posts/the-main-logical-functions-in-tableau
- **Watch:** https://youtu.be/25xdx28ycFI

I walk through the core logical functions in Tableau: IF, THEN, ELSE, ELSEIF, AND, and OR, using a mock film genre revenue dataset. I also cover the shorthand IFNULL and IIF functions, showing how to write each as a row-level calculation and explaining where each is appropriate.

## Key takeaways

- 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.

## Chapters

- 0:22 Setting up the dataset
- 1:24 Writing your first IF statement
- 6:45 Chaining conditions with ELSEIF
- 11:29 Using AND and OR statements
- 16:09 AND pitfalls at row level
- 20:08 The IFNULL shorthand
- 23:32 The IIF function
- 25:25 Why these functions matter

Watch the full video, read the transcript and use chapter deep-links on the page: https://just-tim.com/posts/the-main-logical-functions-in-tableau

---
just-tim — Data and analytics, with a point of view. · https://www.youtube.com/channel/UC7HYxRWmaNlJux-X7rNLZyw · https://twitter.com/TableauTim · https://www.linkedin.com/in/timngwena
