ACOS(number) is the arccosine: the angle, in radians, whose cosine is the number, so ACOS(-1) is π. It only makes sense for numbers from -1 to 1. Outside that range Tableau gives null, while DuckDB's acos() stops the whole query with an error, so the SQL needs a guard: CASE WHEN x BETWEEN -1 AND 1 THEN acos(x) END.
Updated · Checked on the xmetric engine
What is the syntax?
ACOS(number)
number
a number from -1 to 1, usually a cosine or a ratio.
Returns a number of radians from 0 to π. Null if the input is null or outside -1 to 1.
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 angle has each ratio as its cosine?
Tableau
ACOS([Ratio])
SQL (DuckDB)
SELECTCASEWHEN Ratio BETWEEN-1AND1THENacos(Ratio) ENDAS result
FROM input
ORDERBY id
-1 gives π (3.14159), 1 gives 0 and 0.5 gives π/3. Row 7 is 1.5, outside the range, so it returns null; row 6 has no ratio.
Ratio
Result
0.5
1.05
−0.5
2.09
1
0
−1
3.14
0
1.57
null
1.5
null
−0.8
2.5
✓ The Tableau formula and the SQL return the same 8 rows.
What is that angle in degrees?
Tableau
DEGREES(ACOS([Ratio]))
SQL (DuckDB)
SELECTCASEWHEN Ratio BETWEEN-1AND1THENdegrees(acos(Ratio))
ENDAS result
FROM input
ORDERBY id
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does clamping the input give an angle where Tableau gives null?
The quick fix for DuckDB's out-of-range error is to clamp the input into -1 to 1. That turns row 7's 1.5 into 1 and returns 0, an angle Tableau never produced. Guard with CASE instead, so out-of-range values stay null.
Tableau
ACOS([Ratio])
Tempting SQL
SELECTacos(least(1, greatest(-1, Ratio))) AS result
FROM input
ORDERBY id
SQL that matches
SELECTCASEWHEN Ratio BETWEEN-1AND1THENacos(Ratio) ENDAS result
FROM input
ORDERBY id
Ratio
Tableau
Tempting SQL
SQL that matches
0.5
1.05
1.05
1.05
−0.5
2.09
2.09
2.09
1
0
0
0
−1
3.14
3.14
3.14
0
1.57
1.57
1.57
null
3.14
null
1.5
null
0
null
−0.8
2.5
2.5
2.5
✓ 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 Ratio BETWEEN-1AND1THENACOS(Ratio) ENDAS result
FROM input
ORDERBY id
Null in Tableau: row 7 has a ratio of 1.5, and ACOS returns null there. DuckDB raises an out-of-range error instead, which is why every SQL on this page has a CASE WHEN ... BETWEEN -1 AND 1 guard.
How do I get degrees instead of radians?
Wrap it: DEGREES(ACOS([Ratio])), and in SQL degrees(acos(Ratio)). A ratio of 0.5 gives 60 degrees.
Is ACOS the inverse of COS?
Yes, within 0 to π: ACOS(COS(x)) gives back x only when x is between 0 and π. Outside that range you get the matching angle inside it.