Tableau function Number

Tableau ASIN to SQL

ASIN(number) is the arcsine: the angle, in radians, whose sine is the number, so ASIN(1) is π/2. The input must be from -1 to 1. Outside that range Tableau gives null, while DuckDB's asin() raises an error, so the SQL guards it: CASE WHEN x BETWEEN -1 AND 1 THEN asin(x) END.

Updated · Checked on the xmetric engine

What is the syntax?

ASIN(number)
number
a number from -1 to 1, usually a sine or a ratio.

Returns a number of radians from -π/2 to π/2. Null if the input is null or outside -1 to 1.

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 ratio as its sine?

Tableau

ASIN([Ratio])

SQL (DuckDB)

SELECT
  CASE WHEN Ratio BETWEEN - 1 AND 1 THEN asin(Ratio) END AS result
FROM input
ORDER BY id

1 gives π/2 (1.5708), -1 gives -π/2 and 0.5 gives π/6. Row 7 is 1.5, so it returns null.

RatioResult
0.50.52
−0.5−0.52
11.57
−1−1.57
00
null
1.5null
−0.8−0.93

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

What is that angle in degrees?

Tableau

DEGREES(ASIN([Ratio]))

SQL (DuckDB)

SELECT
  CASE
    WHEN Ratio BETWEEN - 1 AND 1 THEN degrees(asin(Ratio))
    END AS result
FROM input
ORDER BY id

0.5 gives 30 degrees and -1 gives -90.

RatioResult
0.530
−0.5−30
190
−1−90
00
null
1.5null
−0.8−53.13

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

Where does a straight translation go wrong?

Common mistake

Why does clamping the input give an angle where Tableau gives null?

Clamping the ratio into -1 to 1 silences DuckDB's error but turns row 7's 1.5 into 1, so the SQL returns π/2 where Tableau returns null. Keep the out-of-range rows null with CASE.

Tableau

ASIN([Ratio])

Tempting SQL

SELECT asin(least(1, greatest(- 1, Ratio))) AS result
FROM input
ORDER BY id

SQL that matches

SELECT
  CASE WHEN Ratio BETWEEN - 1 AND 1 THEN asin(Ratio) END AS result
FROM input
ORDER BY id
RatioTableauTempting SQLSQL that matches
0.50.520.520.52
−0.5−0.52−0.52−0.52
11.571.571.57
−1−1.57−1.57−1.57
0000
null−1.57null
1.5null1.57null
−0.8−0.93−0.93−0.93

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 Ratio BETWEEN - 1 AND 1 THEN ASIN(Ratio) END AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT SAFE.ASIN(Ratio) AS result
FROM input
ORDER BY id

BigQuery documentation

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

What does ASIN return outside -1 to 1?

Null in Tableau: row 7's ratio is 1.5, and ASIN returns null. DuckDB raises an error there, so the SQL keeps a BETWEEN -1 AND 1 guard.

How do I get degrees?

DEGREES(ASIN([Ratio])); in SQL degrees(asin(Ratio)). A ratio of 0.5 is 30 degrees.

Why is ASIN of -0.8 negative?

ASIN returns angles from -π/2 to π/2, so negative ratios give negative angles: -0.8 is about -0.927 radians.

Where is this documented?