Tableau function Logical

Tableau ISNULL to SQL

ISNULL(expression) returns true when the expression is null and false otherwise. In SQL write x IS NULL. The tempting x = NULL compiles but returns null on every row, because nothing equals null, not even null.

Updated · Checked on the xmetric engine

What is the syntax?

ISNULL(expression)
expression
any field or expression.

Returns a boolean: true if the expression is null, false otherwise. Never null.

What does it return, and what is the SQL?

Each example runs on the same 6 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.

Which rows have no score?

Tableau

ISNULL([Score])

SQL (DuckDB)

SELECT Score IS NULL AS result
FROM input
ORDER BY id

Only row 4 is missing its score.

ScoreResult
92false
80false
50false
true
45false
80false

The Tableau formula and the SQL return the same 6 rows.

How do I label missing scores?

Tableau

IIF(ISNULL([Score]), 'missing', 'ok')

SQL (DuckDB)

SELECT
  CASE WHEN Score IS NULL THEN 'missing' ELSE 'ok' END AS result
FROM input
ORDER BY id

Row 4 says missing; the rest say ok.

ScoreResult
92ok
80ok
50ok
missing
45ok
80ok

The Tableau formula and the SQL return the same 6 rows.

Where does a straight translation go wrong?

Common mistake

Why does Score = NULL return nothing?

Comparing anything to null with = gives null, not true, so the SQL answers null on all six rows. Tableau's ISNULL gives true or false.

Tableau

ISNULL([Score])

Tempting SQL

SELECT Score = NULL AS result
FROM input
ORDER BY id

SQL that matches

SELECT Score IS NULL AS result
FROM input
ORDER BY id
ScoreTableauTempting SQLSQL that matches
92falsenullfalse
80falsenullfalse
50falsenullfalse
truenulltrue
45falsenullfalse
80falsenullfalse

The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.

How do I write it in Snowflake or BigQuery?

The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.

Snowflake

SELECT Score IS NULL AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT Score IS NULL AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own ISNULL formula return?

Edit the formula and run it on the 6 sample rows. Fields: [id], [Region], [Season], [Score], [Flag], [Backup].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about ISNULL?

Is ISNULL the same as IFNULL?

No. ISNULL answers a question (true or false); IFNULL replaces the null with another value.

How do I test for "not null"?

NOT ISNULL([Score]); in SQL Score IS NOT NULL.

Does ISNULL treat an empty string as null?

No. An empty string is a value; ISNULL is false for it. Test [x] = "" separately if blanks should count.

Where is this documented?