SIGN(number) returns -1 for a negative number, 0 for zero and 1 for a positive number; a null stays null. DuckDB, Snowflake and BigQuery all call it sign(). A two-way CASE WHEN x > 0 THEN 1 ELSE -1 END looks equivalent but sends both zero and null to -1.
Updated · Checked on the xmetric engine
What is the syntax?
SIGN(number)
number
a number, a numeric field or an aggregate such as SUM([Qty]).
Returns an integer: -1, 0 or 1. Null if the input 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.
Is each value negative, zero or positive?
Tableau
SIGN([Value])
SQL (DuckDB)
SELECTsign(Value) AS result
FROM input
ORDERBY id
-2.5 gives -1, 0 gives 0, and the null row stays null.
Value
Result
2.5
1
−2.5
−1
0.13
1
−0.4
−1
3.75
1
null
0
0
16
1
✓ The Tableau formula and the SQL return the same 8 rows.
Is each region's total quantity up or down?
Tableau
SIGN(SUM([Qty]))
SQL (DuckDB)
SELECT Region, sign(sum(Qty)) AS result
FROM input
GROUPBY Region
ORDERBY Region
North's quantities add up to -1, so its sign is -1.
Region
Result
East
1
North
−1
West
1
✓ The Tableau formula and the SQL return the same 3 rows.
Where does a straight translation go wrong?
Common mistake
Why does a two-way CASE give -1 for zero?
A CASE with only "> 0" and ELSE has no branch for zero or null, so row 7 (0) and row 6 (null) both become -1.
Tableau
SIGN([Value])
Tempting SQL
SELECTCASEWHEN Value >0THEN1ELSE-1ENDAS result
FROM input
ORDERBY id
SQL that matches
SELECTsign(Value) AS result
FROM input
ORDERBY id
Value
Tableau
Tempting SQL
SQL that matches
2.5
1
1
1
−2.5
−1
−1
−1
0.13
1
1
1
−0.4
−1
−1
−1
3.75
1
1
1
null
−1
null
0
0
−1
0
16
1
1
1
✓ 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.