ATAN(number) returns the angle, in radians, whose tangent is the number; the result is always between -π/2 and π/2. DuckDB, Snowflake and BigQuery all call it atan(). Don't "upgrade" ATAN([y]/[x]) to atan2(y, x) while translating: atan2 keeps the quadrant, so it changes the angle whenever x is negative.
Updated · Checked on the xmetric engine
What is the syntax?
ATAN(number)
number
any number, such as a slope (rise over run).
Returns a number of radians from -π/2 to π/2. 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.
What angle has each value as its tangent?
Tableau
ATAN([Value])
SQL (DuckDB)
SELECTatan(Value) AS result
FROM input
ORDERBY id
ATAN(16) is close to π/2 (1.508); ATAN(0) is 0, and negative values give negative angles.
Value
Result
2.5
1.19
−2.5
−1.19
0.13
0.12
−0.4
−0.38
3.75
1.31
null
0
0
16
1.51
✓ The Tableau formula and the SQL return the same 8 rows.
What is the angle of each slope, rise over run?
Tableau
ATAN([Value]/[Other])
SQL (DuckDB)
SELECTatan(Value / Other) AS result
FROM input
ORDERBY id
Row 8 rises 16 over 16, so its angle is π/4 (0.785). Row 3 has no run, so it is null.
Value
Other
Result
2.5
4
0.56
−2.5
−3
0.69
0.13
null
−0.4
−1
0.38
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.
Where does a straight translation go wrong?
Common mistake
Why does replacing ATAN(y/x) with atan2(y, x) change some angles?
atan2 looks at the signs of both arguments and returns angles from -π to π. ATAN only sees the ratio: rows 2 and 4 have both values negative, so ATAN returns a positive angle (0.69 for row 2) where atan2 returns -2.45. Keep atan() of the ratio to match Tableau.
Tableau
ATAN([Value]/[Other])
Tempting SQL
SELECTatan2(Value, Other) AS result
FROM input
ORDERBY id
SQL that matches
SELECTatan(Value / Other) AS result
FROM input
ORDERBY id
Value
Other
Tableau
Tempting SQL
SQL that matches
2.5
4
0.56
0.56
0.56
−2.5
−3
0.69
−2.45
0.69
0.13
null
null
null
−0.4
−1
0.38
−2.76
0.38
3.75
8
0.44
0.44
0.44
2
null
null
null
0
0.5
0
0
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.