[a] * [x] multiplies, with null when either side is null, the same as SQL. When translating an aggregate, keep the product inside the SUM: SUM([a] * [x]) sums row products, which is not the product of two sums.
Updated · Checked on the xmetric engine
What is the syntax?
a * b
a, b
numbers, numeric fields or aggregates.
Returns a number. Null if either side 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 a * x on each row?
Tableau
[a]*[x]
SQL (DuckDB)
SELECT a * x AS result
FROM input
ORDERBY id
Row 2 is -7 * -2.5 = 17.5.
a
x
Result
7
1.5
10.5
−7
−2.5
17.5
2
0.1
0.2
9
2.25
20.25
5
null
4
null
1
−1
−1
−3
3
−9
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does sum(a) * sum(x) give 102.9?
Multiplying the totals is a different number from summing row products (38.45). Translate SUM([a] * [x]) as sum(a * x).
Tableau
SUM([a]*[x])
Tempting SQL
SELECTsum(a) *sum(x) AS result
FROM input
SQL that matches
SELECTsum(a * x) AS result
FROM input
Tableau
Tempting SQL
SQL that matches
38.45
103
38.45
✓ 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.