Tableau function Number

Tableau ATAN to SQL

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)

SELECT atan(Value) AS result
FROM input
ORDER BY id

ATAN(16) is close to π/2 (1.508); ATAN(0) is 0, and negative values give negative angles.

ValueResult
2.51.19
−2.5−1.19
0.130.12
−0.4−0.38
3.751.31
null
00
161.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)

SELECT atan(Value / Other) AS result
FROM input
ORDER BY id

Row 8 rises 16 over 16, so its angle is π/4 (0.785). Row 3 has no run, so it is null.

ValueOtherResult
2.540.56
−2.5−30.69
0.13null
−0.4−10.38
3.7580.44
2null
00.50
16160.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

SELECT atan2(Value, Other) AS result
FROM input
ORDER BY id

SQL that matches

SELECT atan(Value / Other) AS result
FROM input
ORDER BY id
ValueOtherTableauTempting SQLSQL that matches
2.540.560.560.56
−2.5−30.69−2.450.69
0.13nullnullnull
−0.4−10.38−2.760.38
3.7580.440.440.44
2nullnullnull
00.5000
16160.790.790.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

SELECT ATAN(Value) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT ATAN(Value) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own ATAN formula return?

Edit the formula and run it on the 8 sample rows. Fields: [id], [Region], [Value], [Qty], [Ratio], [Other].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about ATAN?

What is the range of ATAN?

-π/2 to π/2 (-90 to 90 degrees). A slope can't tell "up and to the left" from "down and to the right"; for that, use ATAN2([y], [x]).

Does ATAN take degrees?

No, it returns radians. Wrap it in DEGREES() to get degrees: DEGREES(ATAN(1)) is 45.

What does ATAN return for a null?

Null. Row 6 has no value, so every example is null there.

Where is this documented?