Tableau function Number

Tableau POWER to SQL

POWER(number, power) raises the number to the power: POWER(5, 3) is 125, and [x]^3 is the same thing. DuckDB writes pow() or power(), as do Snowflake and BigQuery; avoid ^ in BigQuery, where it is bitwise XOR. As with any function around an aggregate, POWER(SUM(x), 2) and SUM(POWER(x, 2)) answer different questions.

Updated · Checked on the xmetric engine

What is the syntax?

POWER(number, power)
number
the base.
power
the exponent. It may be negative or fractional.

Returns a number: number raised to power. Null if either 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 is each value cubed?

Tableau

POWER([Value], 3)

SQL (DuckDB)

SELECT pow(Value, 3) AS result
FROM input
ORDER BY id

2.5 cubed is 15.625 and -2.5 cubed is -15.625.

ValueResult
2.515.63
−2.5−15.63
0.130
−0.4−0.06
3.7552.73
null
00
164,096

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

What is the square of each region's total?

Tableau

POWER(SUM([Value]), 2)

SQL (DuckDB)

SELECT Region, pow(sum(Value), 2) AS result
FROM input
GROUP BY Region
ORDER BY Region

West's values add up to 3.35, so the square is 11.22.

RegionResult
East0.02
North256
West11.22

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

Where does a straight translation go wrong?

Common mistake

Why is the sum of squares not the square of the sum?

Squaring each row and then adding gives 12.52 for East; adding first and then squaring gives 0.0156, because East's 2.5 and -2.5 cancel out. Keep POWER outside the SUM, as in the formula.

Tableau

POWER(SUM([Value]), 2)

Tempting SQL

SELECT Region, sum(pow(Value, 2)) AS result
FROM input
GROUP BY Region
ORDER BY Region

SQL that matches

SELECT Region, pow(sum(Value), 2) AS result
FROM input
GROUP BY Region
ORDER BY Region
RegionTableauTempting SQLSQL that matches
East0.0212.520.02
North256256256
West11.2214.2211.22

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

Snowflake documentation

BigQuery

SELECT POW(Value, 3) AS result
FROM input
ORDER BY id

BigQuery documentation

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

Is ^ the same as POWER?

Yes, in Tableau [Value]^2 equals POWER([Value], 2). In SQL, DuckDB's ^ is also a power, but BigQuery's is bitwise XOR, so use POW there.

How do I take a square root with POWER?

POWER([x], 0.5) works for positive numbers, but SQRT is clearer and returns null for negatives.

What does POWER return for a null?

Null. Row 6 has no value.

Where is this documented?