Parentheses make Tableau evaluate the inside first: ([a] + [b]) * 2 adds before multiplying. They carry over to SQL unchanged. Never drop them because the expression looks the same in SQL: -([a] ^ 2) and -[a] ^ 2 differ in both.
Updated · Checked on the xmetric engine
What is the syntax?
(expression)
expression
any part of a formula.
Returns the value of the inner expression, evaluated before the operators around it.
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.
How do I add before multiplying?
Tableau
([a]+[b]) *2
SQL (DuckDB)
SELECT (a + b) *2AS result
FROM input
ORDERBY id
Row 1: (7 + 2) * 2 = 18.
a
b
Result
7
2
18
−7
2
−10
2
5
14
9
4
26
5
3
16
2
null
1
null
−3
−2
−10
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does -a ^ 2 lose the minus sign?
Without parentheses the minus binds first, in Tableau and in DuckDB, so -a ^ 2 is a positive square. -([a] ^ 2) squares first and then negates; keep the parentheses.
Tableau
-([a] ^ 2)
Tempting SQL
SELECT- a ^ 2AS result
FROM input
ORDERBY id
SQL that matches
SELECT- (a ^ 2) AS result
FROM input
ORDERBY id
a
Tableau
Tempting SQL
SQL that matches
7
−49
49
−49
−7
−49
49
−49
2
−4
4
−4
9
−81
81
−81
5
−25
25
−25
null
null
null
1
−1
1
−1
−3
−9
9
−9
✓ 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.