Tableau function Number

Tableau LEASTPROPAGATENULL to SQL

LEASTPROPAGATENULL(expr1, expr2, ...) returns the smallest argument, but null as soon as any argument is null. DuckDB's least() skips nulls, so it needs a guard: CASE WHEN a IS NULL OR b IS NULL THEN NULL ELSE least(a, b) END. Snowflake's and BigQuery's plain LEAST already propagate nulls.

Updated · Checked on the xmetric engine

What is the syntax?

LEASTPROPAGATENULL(expr1, expr2, ...)
expr1, expr2, ...
two or more numbers or numeric expressions.

Returns the smallest 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 smaller, unless a value is missing?

Tableau

LEASTPROPAGATENULL([Value], [Other])

SQL (DuckDB)

SELECT
  CASE
    WHEN Value IS NULL OR Other IS NULL THEN NULL
    ELSE least(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 LEAST.

ValueOtherResult
2.542.5
−2.5−3−3
0.13null
−0.4−1−1
3.7583.75
2null
00.50
161616

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

Where does a straight translation go wrong?

Common mistake

Why does least() return a value where Tableau returns null?

DuckDB's least() skips nulls, which is Tableau's plain LEAST. Rows 3 and 6 get 0.125 and 2 in the SQL but null in Tableau.

Tableau

LEASTPROPAGATENULL([Value], [Other])

Tempting SQL

SELECT least(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 least(Value, Other)
    END AS result
FROM input
ORDER BY id
ValueOtherTableauTempting SQLSQL that matches
2.542.52.52.5
−2.5−3−3−3−3
0.13null0.13null
−0.4−1−1−1−1
3.7583.753.753.75
2null2null
00.5000
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 LEAST(Value, Other) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

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

BigQuery documentation

What does your own LEASTPROPAGATENULL 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 LEASTPROPAGATENULL?

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 LEASTPROPAGATENULL?

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

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?