POWER: from Tableau to SQL

Raises a number to a power. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

POWER([amount], 2)

Sample data

idamountunitsscoreother
1-2.52-0.83
20004
31.530.252
4440.58
5950.811
6166114
7null7null9
848-0.5null

The same calculation as SQL

SELECT power(amount,2) AS result FROM input ORDER BY id

Runs the example above.

Result

idamountunitsscoreresult
1-2.52-0.86.25
20000
31.530.252.25
4440.516
5950.881
61661256
7null7nullnull
848-0.516

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • Replacing null results with zero changes missing-value semantics.

    Naive SQL

    SELECT coalesce((power(amount,2)),0) AS result FROM input ORDER BY id
    idamountunitsscoreresult
    1-2.52-0.86.25
    20000
    31.530.252.25
    4440.516
    5950.881
    61661256
    7null7null0
    848-0.516

    Matches the calculation

    SELECT power(amount,2) AS result FROM input ORDER BY id
    idamountunitsscoreresult
    1-2.52-0.86.25
    20000
    31.530.252.25
    4440.516
    5950.881
    61661256
    7null7nullnull
    848-0.516

Signature

POWER(number, number)