[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
ORDERBY id
Rows 6 and 7 each miss one value, so they return null.
a
b
Result
7
2
9
−7
2
−5
2
5
7
9
4
13
5
3
8
2
null
1
null
−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
ORDERBY id
The result is a decimal: row 1 is 8.5.
a
x
Result
7
1.5
8.5
−7
−2.5
−9.5
2
0.1
2.1
9
2.25
11.25
5
null
4
null
1
−1
0
−3
3
0
✓ 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
SELECTsum(a) +sum(b) AS result
FROM input
SQL that matches
SELECTsum(a + b) AS result
FROM input
Tableau
Tempting SQL
SQL that matches
27
30
27
✓ 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.