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)
SELECTpow(Value, 3) AS result
FROM input
ORDERBY id
2.5 cubed is 15.625 and -2.5 cubed is -15.625.
Value
Result
2.5
15.63
−2.5
−15.63
0.13
0
−0.4
−0.06
3.75
52.73
null
0
0
16
4,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
GROUPBY Region
ORDERBY Region
West's values add up to 3.35, so the square is 11.22.
Region
Result
East
0.02
North
256
West
11.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
GROUPBY Region
ORDERBY Region
SQL that matches
SELECT Region, pow(sum(Value), 2) AS result
FROM input
GROUPBY Region
ORDERBY Region
Region
Tableau
Tempting SQL
SQL that matches
East
0.02
12.52
0.02
North
256
256
256
West
11.22
14.22
11.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
SELECTPOWER(Value, 3) AS result
FROM input
ORDERBY id