SQRT(number) returns the square root: SQRT(25) is 5. A negative number has no real square root and Tableau returns null; DuckDB's sqrt() raises an error, so the SQL is CASE WHEN x >= 0 THEN sqrt(x) END. Rewriting it as pow(x, 0.5) avoids the error but returns NaN instead of null.
Updated · Checked on the xmetric engine
What is the syntax?
SQRT(number)
number
a number, zero or above.
Returns a non-negative number. Null if the input is null or negative.
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 the square root of each value?
Tableau
SQRT([Value])
SQL (DuckDB)
SELECTCASEWHEN Value >=0THENsqrt(Value) ENDAS result
FROM input
ORDERBY id
SQRT(16) is 4 and SQRT(0) is 0. The negatives return null.
Value
Result
2.5
1.58
−2.5
null
0.13
0.35
−0.4
null
3.75
1.94
null
0
0
16
4
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does pow(x, 0.5) show NaN where Tableau shows null?
A fractional power of a negative number is not a number, and DuckDB returns NaN for rows 2 and 4. NaN is not null: it survives filters on IS NULL and turns sums into NaN. Tableau's SQRT gives null.
Tableau
SQRT([Value])
Tempting SQL
SELECTpow(Value, 0.5) AS result
FROM input
ORDERBY id
SQL that matches
SELECTCASEWHEN Value >=0THENsqrt(Value) ENDAS result
FROM input
ORDERBY id
Value
Tableau
Tempting SQL
SQL that matches
2.5
1.58
1.58
1.58
−2.5
null
NaN
null
0.13
0.35
0.35
0.35
−0.4
null
NaN
null
3.75
1.94
1.94
1.94
null
null
null
0
0
0
0
16
4
4
4
✓ 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
SELECTCASEWHEN Value >=0THENSQRT(Value) ENDAS result
FROM input
ORDERBY id