Tableau function Number

Tableau PI to SQL

PI() takes no argument and returns π, 3.141592653589793. DuckDB and Snowflake have pi(); BigQuery has no PI function, and ACOS(-1) gives the same number. The trap is the shortcut: 3.14 or 3.1416 in hand-written SQL makes every area and angle slightly different from Tableau's.

Updated · Checked on the xmetric engine

What is the syntax?

PI()
(none)
PI takes no arguments, but the parentheses are required.

Returns the number π (3.141592653589793).

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 does PI() return on every row?

Tableau

PI()

SQL (DuckDB)

SELECT pi() AS result
FROM input
ORDER BY id

The same constant on each of the 8 rows.

Result
3.14
3.14
3.14
3.14
3.14
3.14
3.14
3.14

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

What is the area of a circle with each value as its radius?

Tableau

PI() * SQUARE([Value])

SQL (DuckDB)

SELECT pi() * Value * Value AS result
FROM input
ORDER BY id

A radius of 16 gives 804.25; the null row stays null.

ValueResult
2.519.63
−2.519.63
0.130.05
−0.40.5
3.7544.18
null
00
16804

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

Where does a straight translation go wrong?

Common mistake

Why is the area slightly off with 3.14?

Hard-coding 3.14 shaves 0.05% off every result: a radius of 16 gives 803.84 instead of Tableau's 804.25.

Tableau

PI() * SQUARE([Value])

Tempting SQL

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

SQL that matches

SELECT pi() * Value * Value AS result
FROM input
ORDER BY id
ValueTableauTempting SQLSQL that matches
2.519.6319.6319.63
−2.519.6319.6319.63
0.130.050.050.05
−0.40.50.50.5
3.7544.1844.1644.18
nullnullnull
0000
16804804804

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

Snowflake documentation

BigQuery

SELECT ACOS(- 1) * POW(Value, 2) AS result
FROM input
ORDER BY id

BigQuery documentation

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

Does PI need parentheses?

Yes, in Tableau and in SQL: PI(). In DuckDB a bare pi is read as a column name.

What is PI() in BigQuery?

There is no PI function; use ACOS(-1), which returns π to full double precision.

Is PI() an aggregate?

No, it is a constant, so it can sit next to aggregates or row-level fields: PI() * SQUARE(SUM([r])) works.

Where is this documented?