Tableau function Number

Tableau COT to SQL

COT(number) is the cotangent, 1 divided by the tangent, of an angle in radians: COT(PI()/4) is 1. At 0 the cotangent is undefined and Tableau returns null. DuckDB's cot(0) raises an error and 1/tan(0) returns infinity, so guard the zero: CASE WHEN x <> 0 THEN cot(x) END.

Updated · Checked on the xmetric engine

What is the syntax?

COT(number)
number
an angle in radians.

Returns a number. Null if the input is null or the cotangent is undefined (an angle of 0).

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 cotangent of each angle?

Tableau

COT([Value])

SQL (DuckDB)

SELECT CASE WHEN Value <> 0 THEN cot(Value) END AS result
FROM input
ORDER BY id

0.125 radians gives 7.96; row 7 (0) and row 6 (null) return null.

ValueResult
2.5−1.34
−2.51.34
0.137.96
−0.4−2.37
3.751.44
null
0null
163.33

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

Where does a straight translation go wrong?

Common mistake

Why does 1/tan(x) show infinity where Tableau shows null?

The textbook identity divides by tan(0) = 0 on row 7. DuckDB returns infinity for that division, while Tableau's COT returns null.

Tableau

COT([Value])

Tempting SQL

SELECT 1 / tan(Value) AS result
FROM input
ORDER BY id

SQL that matches

SELECT CASE WHEN Value <> 0 THEN cot(Value) END AS result
FROM input
ORDER BY id
ValueTableauTempting SQLSQL that matches
2.5−1.34−1.34−1.34
−2.51.341.341.34
0.137.967.967.96
−0.4−2.37−2.37−2.37
3.751.441.441.44
nullnullnull
0null+Infinitynull
163.333.333.33

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 CASE WHEN Value <> 0 THEN COT(Value) END AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT CASE WHEN Value <> 0 THEN COT(Value) END AS result
FROM input
ORDER BY id

BigQuery documentation

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

What does COT return at 0?

Null: row 7 has an angle of 0. In DuckDB cot(0) stops the query with an error, which is why the SQL checks Value <> 0 first.

Is COT the same as 1/TAN?

Everywhere except where the tangent is 0. There, 1/tan(x) gives infinity and Tableau gives null.

Does COT take degrees?

No, radians. Use COT(RADIANS([Angle])) for degrees.

Where is this documented?