GREATESTPROPAGATENULL(expr1, expr2, ...) returns the largest argument, but null as soon as any argument is null. DuckDB's greatest() skips nulls, so it needs a guard: CASE WHEN a IS NULL OR b IS NULL THEN NULL ELSE greatest(a, b) END. Snowflake's and BigQuery's plain GREATEST already propagate nulls.
Updated · Checked on the xmetric engine
What is the syntax?
GREATESTPROPAGATENULL(expr1, expr2, ...)
expr1, expr2, ...
two or more numbers or numeric expressions.
Returns the largest argument, or null if any argument is null.
What does it return, and what is the SQL?
Each example runs on the same 8 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
Which is larger, unless a value is missing?
Tableau
GREATESTPROPAGATENULL([Value], [Other])
SQL (DuckDB)
SELECTCASEWHEN Value ISNULLOR Other ISNULLTHENNULLELSEgreatest(Value, Other)
ENDAS result
FROM input
ORDERBY id
Rows 3 and 6 each miss one value, so both return null. The other rows match plain GREATEST.
Value
Other
Result
2.5
4
4
−2.5
−3
−2.5
0.13
null
−0.4
−1
−0.4
3.75
8
8
2
null
0
0.5
0.5
16
16
16
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does greatest() return a value where Tableau returns null?
DuckDB's greatest() skips nulls, which is Tableau's plain GREATEST. Rows 3 and 6 get 0.125 and 2 in the SQL but null in Tableau.
Tableau
GREATESTPROPAGATENULL([Value], [Other])
Tempting SQL
SELECTgreatest(Value, Other) AS result
FROM input
ORDERBY id
SQL that matches
SELECTCASEWHEN Value ISNULLOR Other ISNULLTHENNULLELSEgreatest(Value, Other)
ENDAS result
FROM input
ORDERBY id
Value
Other
Tableau
Tempting SQL
SQL that matches
2.5
4
4
4
4
−2.5
−3
−2.5
−2.5
−2.5
0.13
null
0.13
null
−0.4
−1
−0.4
−0.4
−0.4
3.75
8
8
8
8
2
null
2
null
0
0.5
0.5
0.5
0.5
16
16
16
16
16
✓ 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
SELECTGREATEST(Value, Other) AS result
FROM input
ORDERBY id