Tableau function Operators

Tableau unary - (negate) to SQL

-[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.

Updated · Checked on the xmetric engine

What is the syntax?

-a
a
a number, numeric field or aggregate.

Returns the number with its sign flipped. Null if a 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 minus a on each row?

Tableau

-[a]

SQL (DuckDB)

SELECT - a AS result
FROM input
ORDER BY id

Row 2 turns -7 into 7; row 6 stays null.

aResult
7−7
−77
2−2
9−9
5−5
null
1−1
−33

The Tableau formula and the SQL return the same 8 rows.

How do I negate a total?

Tableau

-SUM([x])

SQL (DuckDB)

SELECT - sum(x) AS result
FROM input

The 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.

Where does a straight translation go wrong?

Common mistake

Why does -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] ^ 2

Tempting SQL

SELECT - power(x, 2) AS result
FROM input
ORDER BY id

SQL that matches

SELECT power(- x, 2) AS result
FROM input
ORDER BY id
xTableauTempting SQLSQL that matches
1.52.25−2.252.25
−2.56.25−6.256.25
0.10.01−0.010.01
2.255.06−5.065.06
nullnullnull
416−1616
−11−11
39−99

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

Snowflake documentation

BigQuery

SELECT - a AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own unary - 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 unary -?

Is -[a] the same as 0 - [a]?

Yes for every number, and both keep a null as null.

Can I negate a boolean?

No; use NOT.

Where is this documented?