Tableau function Operators

Tableau parentheses ( ) in SQL

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) * 2 AS result
FROM input
ORDER BY id

Row 1: (7 + 2) * 2 = 18.

abResult
7218
−72−10
2514
9426
5316
2null
1null
−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 ^ 2 AS result
FROM input
ORDER BY id

SQL that matches

SELECT - (a ^ 2) AS result
FROM input
ORDER BY id
aTableauTempting SQLSQL that matches
7−4949−49
−7−4949−49
2−44−4
9−8181−81
5−2525−25
nullnullnull
1−11−1
−3−99−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.

Snowflake

SELECT (a + b) * 2 AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT (a + b) * 2 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 ( )?

Are extra parentheses harmful?

No. They only change the result when they change the order of evaluation.

Do parentheses change null handling?

No. A null inside still makes the whole arithmetic result null.

Where is this documented?