ATAN2(y, x) returns the angle, in radians from -π to π, between the positive x axis and the point (x, y). The y coordinate comes first. DuckDB, Snowflake and BigQuery take the same order, atan2(y, x), but Excel and some libraries take x first, so copying the arguments from a spreadsheet swaps them silently.
Updated · Checked on the xmetric engine
What is the syntax?
ATAN2(y_number, x_number)
y_number
the vertical coordinate (first).
x_number
the horizontal coordinate (second).
Returns a number of radians from -π to π. Null if either argument 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 the angle of each point?
Tableau
ATAN2([Value], [Other])
SQL (DuckDB)
SELECTatan2(Value, Other) AS result
FROM input
ORDERBY id
Value is y and Other is x. Row 8 (16, 16) is π/4; row 2 (-2.5 over -3) is in the third quadrant, -2.45.
Value
Other
Result
2.5
4
0.56
−2.5
−3
−2.45
0.13
null
−0.4
−1
−2.76
3.75
8
0.44
2
null
0
0.5
0
16
16
0.79
✓ The Tableau formula and the SQL return the same 8 rows.
What is that angle in degrees?
Tableau
DEGREES(ATAN2([Value], [Other]))
SQL (DuckDB)
SELECTdegrees(atan2(Value, Other)) AS result
FROM input
ORDERBY id
Row 8 is 45 degrees; row 2 is about -140.
Value
Other
Result
2.5
4
32.01
−2.5
−3
−14
0.13
null
−0.4
−1
−158
3.75
8
25.11
2
null
0
0.5
0
16
16
45
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why do the angles change when the arguments are swapped?
Tableau reads the first argument as y. Written x first (the Excel order), the SQL measures the angle from the other axis: row 1 becomes 1.01 instead of 0.56. Keep y first.
Tableau
ATAN2([Value], [Other])
Tempting SQL
SELECTatan2(Other, Value) AS result
FROM input
ORDERBY id
SQL that matches
SELECTatan2(Value, Other) AS result
FROM input
ORDERBY id
Value
Other
Tableau
Tempting SQL
SQL that matches
2.5
4
0.56
1.01
0.56
−2.5
−3
−2.45
−2.27
−2.45
0.13
null
null
null
−0.4
−1
−2.76
−1.95
−2.76
3.75
8
0.44
1.13
0.44
2
null
null
null
0
0.5
0
1.57
0
16
16
0.79
0.79
0.79
✓ 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
SELECTATAN2(Value, Other) AS result
FROM input
ORDERBY id