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 ISNULLAS result
FROM input
ORDERBY id
Only row 4 is missing its score.
Score
Result
92
false
80
false
50
false
true
45
false
80
false
✓ 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)
SELECTCASEWHEN Score ISNULLTHEN'missing'ELSE'ok'ENDAS result
FROM input
ORDERBY id
Row 4 says missing; the rest say ok.
Score
Result
92
ok
80
ok
50
ok
missing
45
ok
80
ok
✓ 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 =NULLAS result
FROM input
ORDERBY id
SQL that matches
SELECT Score ISNULLAS result
FROM input
ORDERBY id
Score
Tableau
Tempting SQL
SQL that matches
92
false
null
false
80
false
null
false
50
false
null
false
true
null
true
45
false
null
false
80
false
null
false
✓ 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 ISNULLAS result
FROM input
ORDERBY id