What is minus a on each row?
Tableau
-[a]SQL (DuckDB)
SELECT - a AS result
FROM input
ORDER BY idRow 2 turns -7 into 7; row 6 stays null.
| a | Result |
|---|---|
| 7 | −7 |
| −7 | 7 |
| 2 | −2 |
| 9 | −9 |
| 5 | −5 |
| null | |
| 1 | −1 |
| −3 | 3 |
The Tableau formula and the SQL return the same 8 rows.
Tableau function Operators
-[a] changes the sign of a, and a null stays null, exactly as -a in SQL. It has the highest precedence in Tableau, above ^: -[x] ^ 2 squares -x. A -power(x, 2) rewrite negates after squaring.
-aaReturns the number with its sign flipped. Null if a is null.
Each example runs on the same 8 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
Tableau
-[a]SQL (DuckDB)
SELECT - a AS result
FROM input
ORDER BY idRow 2 turns -7 into 7; row 6 stays null.
| a | Result |
|---|---|
| 7 | −7 |
| −7 | 7 |
| 2 | −2 |
| 9 | −9 |
| 5 | −5 |
| null | |
| 1 | −1 |
| −3 | 3 |
The Tableau formula and the SQL return the same 8 rows.
Tableau
-SUM([x])SQL (DuckDB)
SELECT - sum(x) AS result
FROM inputThe sum of x is 7.35, so the result is -7.35.
| Result |
|---|
| −7.35 |
The Tableau formula and the SQL return the same 1 rows.
Common mistake
-power(x, 2) give negative squares?In Tableau the minus binds before ^, so -[x] ^ 2 is (-x)^2, never negative. -power(x, 2) negates the square.
Tableau
-[x] ^ 2Tempting SQL
SELECT - power(x, 2) AS result
FROM input
ORDER BY idSQL that matches
SELECT power(- x, 2) AS result
FROM input
ORDER BY id| x | Tableau | Tempting SQL | SQL that matches |
|---|---|---|---|
| 1.5 | 2.25 | −2.25 | 2.25 |
| −2.5 | 6.25 | −6.25 | 6.25 |
| 0.1 | 0.01 | −0.01 | 0.01 |
| 2.25 | 5.06 | −5.06 | 5.06 |
| null | null | null | |
| 4 | 16 | −16 | 16 |
| −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.
The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.
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.
Yes for every number, and both keep a null as null.
No; use NOT.