Tableau function Operators

Tableau + (add) to SQL

[a] + [b] adds two numbers, and a null on either side makes the result null, in Tableau and in SQL alike. The trap is aggregation: SUM([a] + [b]) drops whole rows where either value is null, while SUM([a]) + SUM([b]) keeps every value.

Updated · Checked on the xmetric engine

What is the syntax?

a + b
a, b
numbers, numeric fields or aggregates.

Returns a number. Null if either side 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.

What is a + b on each row?

Tableau

[a] + [b]

SQL (DuckDB)

SELECT a + b AS result
FROM input
ORDER BY id

Rows 6 and 7 each miss one value, so they return null.

abResult
729
−72−5
257
9413
538
2null
1null
−3−2−5

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

What happens when an integer meets a decimal?

Tableau

[a] + [x]

SQL (DuckDB)

SELECT a + x AS result
FROM input
ORDER BY id

The result is a decimal: row 1 is 8.5.

axResult
71.58.5
−7−2.5−9.5
20.12.1
92.2511.25
5null
4null
1−10
−330

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

Where does a straight translation go wrong?

Common mistake

Why is sum(a) + sum(b) bigger than SUM([a] + [b])?

Inside SUM, a + b is null on rows 6 and 7, so their other value is lost too: 22. Summing each column first keeps them: 25. Keep the SUM where Tableau has it.

Tableau

SUM([a] + [b])

Tempting SQL

SELECT sum(a) + sum(b) AS result
FROM input

SQL that matches

SELECT sum(a + b) AS result
FROM input
TableauTempting SQLSQL that matches
273027

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 a + b AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT a + b AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own + formula return?

Edit the formula and run it on the 8 sample rows. Fields: [id], [a], [b], [x], [p], [q], [s], [t], [d], [e].

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

Which functions go with it?

What do people ask about +?

How do I treat a missing value as zero?

ZN([a]) + ZN([b]); in SQL, coalesce(a, 0) + coalesce(b, 0).

Does + mix integers and decimals?

Yes. [a] + [x] returns a decimal: 7 + 1.5 is 8.5.

Is + also used for text and dates?

Yes: see + (string) and + (date).

Where is this documented?