Tableau function Number

Tableau DEGREES to SQL

DEGREES(number) turns an angle in radians into degrees: DEGREES(PI()/4) is 45. DuckDB and Snowflake have degrees(); BigQuery has no such function, so multiply by 180 / ACOS(-1). Use the full π: writing x * 180 / 3.14 drifts by about 0.05% and the results stop matching Tableau.

Updated · Checked on the xmetric engine

What is the syntax?

DEGREES(number)
number
an angle in radians.

Returns a number of degrees. 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.

How many degrees is each angle?

Tableau

DEGREES([Value])

SQL (DuckDB)

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

2.5 radians is 143.24 degrees; 16 radians is 916.73, more than two full turns.

ValueResult
2.5143
−2.5−143
0.137.16
−0.4−22.92
3.75215
null
00
16917

The Tableau formula and the SQL return the same 8 rows.

What direction does each point face, in degrees?

Tableau

DEGREES(ATAN2([Value], [Other]))

SQL (DuckDB)

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

Row 8 (16 over 16) faces 45 degrees.

ValueOtherResult
2.5432.01
−2.5−3−14
0.13null
−0.4−1−158
3.75825.11
2null
00.50
161645

The Tableau formula and the SQL return the same 8 rows.

Where does a straight translation go wrong?

Common mistake

Why are the degrees slightly off with 3.14?

Hand-written conversions often hard-code π. 180/3.14 overshoots: 2.5 radians becomes 143.31 instead of 143.24. Use degrees() or pi().

Tableau

DEGREES([Value])

Tempting SQL

SELECT Value * 180 / 3.14 AS result
FROM input
ORDER BY id

SQL that matches

SELECT degrees(Value) AS result
FROM input
ORDER BY id
ValueTableauTempting SQLSQL that matches
2.5143143143
−2.5−143−143−143
0.137.167.177.16
−0.4−22.92−22.93−22.92
3.75215215215
nullnullnull
0000
16917917917

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 DEGREES(Value) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT Value * 180 / ACOS(- 1) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own DEGREES 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 DEGREES?

How do I convert the other way?

With RADIANS([Degrees]); in SQL radians(Degrees).

Why are ATAN2 degrees negative?

DEGREES(ATAN2(y, x)) returns -180 to 180. For a 0 to 360 bearing, add 360 to the negative results.

What does DEGREES return for a null?

Null. Row 6 has no value.

Where is this documented?