Tableau function Number

Tableau EXP to SQL

EXP(number) returns e (2.71828) raised to the number: EXP(2) is 7.389. DuckDB, Snowflake and BigQuery all call it exp(). It is the inverse of LN, and Tableau's product idiom EXP(SUM(LN([x]))) relies on LN returning null for zero and negatives, so those rows drop out. SQL's product() keeps them.

Updated · Checked on the xmetric engine

What is the syntax?

EXP(number)
number
the exponent.

Returns a positive number: e to the power of the input. Null if the input 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 e raised to each value?

Tableau

EXP([Value])

SQL (DuckDB)

SELECT exp(Value) AS result
FROM input
ORDER BY id

EXP(0) is 1 and EXP(2.5) is 12.18; EXP(16) is 8.9 million.

ValueResult
2.512.18
−2.50.08
0.131.13
−0.40.67
3.7542.52
null
01
168,886,111

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

What is the product of the positive values per region?

Tableau

EXP(SUM(LN([Value])))

SQL (DuckDB)

SELECT
  Region,
  exp(sum(CASE WHEN Value > 0 THEN ln(Value) END)) AS result
FROM input
GROUP BY Region
ORDER BY Region

East multiplies 2.5 by 0.125 (0.3125): LN skips the -2.5, so the SQL must skip it too.

RegionResult
East0.31
North16
West3.75

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

Where does a straight translation go wrong?

Common mistake

Why does product() give a different total than EXP(SUM(LN()))?

The Tableau idiom silently drops rows where LN is null (zero and negatives). DuckDB's product() multiplies them all: East becomes -0.78 instead of 0.3125, and North 0 instead of 16.

Tableau

EXP(SUM(LN([Value])))

Tempting SQL

SELECT Region, product(Value) AS result
FROM input
GROUP BY Region
ORDER BY Region

SQL that matches

SELECT
  Region,
  exp(sum(CASE WHEN Value > 0 THEN ln(Value) END)) AS result
FROM input
GROUP BY Region
ORDER BY Region
RegionTableauTempting SQLSQL that matches
East0.31−0.780.31
North16016
West3.75−1.53.75

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

Snowflake documentation

BigQuery

SELECT EXP(Value) AS result
FROM input
ORDER BY id

BigQuery documentation

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

How do I multiply values in Tableau?

There is no PRODUCT aggregate, so the idiom is EXP(SUM(LN([x]))). It only works for positive values: LN of zero or a negative is null and is skipped.

Is EXP the inverse of LN?

Yes: EXP(LN(x)) is x for any positive x.

What does EXP return for a null?

Null. Row 6 has no value.

Where is this documented?