Tableau function Number

Tableau GREATESTPROPAGATENULL to SQL

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)

SELECT
  CASE
    WHEN Value IS NULL OR Other IS NULL THEN NULL
    ELSE greatest(Value, Other)
    END AS result
FROM input
ORDER BY id

Rows 3 and 6 each miss one value, so both return null. The other rows match plain GREATEST.

ValueOtherResult
2.544
−2.5−3−2.5
0.13null
−0.4−1−0.4
3.7588
2null
00.50.5
161616

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

SELECT greatest(Value, Other) AS result
FROM input
ORDER BY id

SQL that matches

SELECT
  CASE
    WHEN Value IS NULL OR Other IS NULL THEN NULL
    ELSE greatest(Value, Other)
    END AS result
FROM input
ORDER BY id
ValueOtherTableauTempting SQLSQL that matches
2.54444
−2.5−3−2.5−2.5−2.5
0.13null0.13null
−0.4−1−0.4−0.4−0.4
3.758888
2null2null
00.50.50.50.5
1616161616

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 GREATEST(Value, Other) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT GREATEST(Value, Other) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own GREATESTPROPAGATENULL formula return?

Edit the formula and run it on the 8 sample rows. Fields: [id], [Region], [Value], [Qty], [Ratio], [Other].

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

Which functions go with it?

What do people ask about GREATESTPROPAGATENULL?

When would I want the null back?

When a missing input means the answer is unknown. Picking the other value would hide the gap, which matters for audits and data checks.

Which SQL engines behave like GREATESTPROPAGATENULL?

Snowflake's and BigQuery's GREATEST return null if any argument is null. DuckDB and PostgreSQL skip nulls, like Tableau's plain GREATEST.

What happens with three or more arguments?

The same rule: any null among them makes the result null. In DuckDB add each one to the IS NULL check.

Where is this documented?