Tableau evaluates operators in this order: unary -; ^; *, /, %; +, -; comparisons; NOT; AND; OR. DuckDB uses the same order, so [a] + [b] * 2 and [p] OR [q] AND NOT [p] translate as written. The one surprise is the minus sign: it binds tighter than ^, which a power() rewrite loses.
Updated · Checked on the xmetric engine
What is the syntax?
- (negate), ^, */%, +-, comparisons, NOT, AND, OR
levels
unary minus binds tightest; OR binds loosest. Use parentheses to change the order.
Returns the order in which a formula with several operators is evaluated, highest first.
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.
Is multiplication done before addition?
Tableau
[a]+[b]*2
SQL (DuckDB)
SELECT a + b *2AS result
FROM input
ORDERBY id
Row 1: 7 + 4 = 11, not 18.
a
b
Result
7
2
11
−7
2
−3
2
5
12
9
4
17
5
3
11
2
null
1
null
−3
−2
−7
✓ The Tableau formula and the SQL return the same 8 rows.
Is AND evaluated before OR?
Tableau
[a]=[b]OR[a]>5AND[b]<3
SQL (DuckDB)
SELECT a = b OR a >5AND b <3AS result
FROM input
ORDERBY id
Read as a = b OR (a > 5 AND b < 3): only row 1 passes.
a
b
Result
7
2
true
−7
2
false
2
5
false
9
4
false
5
3
false
2
null
1
null
−3
−2
false
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does moving ^ into power() change the sign?
The minus is the tightest operator, so -[a] ^ 2 + [b] squares -a. -power(a, 2) + b negates the square instead.
Tableau
-[a] ^ 2+[b]
Tempting SQL
SELECT-power(a, 2) + b AS result
FROM input
ORDERBY id
SQL that matches
SELECTpower(- a, 2) + b AS result
FROM input
ORDERBY id
a
b
Tableau
Tempting SQL
SQL that matches
7
2
51
−47
51
−7
2
51
−47
51
2
5
9
1
9
9
4
85
−77
85
5
3
28
−22
28
2
null
null
null
1
null
null
null
−3
−2
7
−11
7
✓ 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.