Tableau function Level of detail

Tableau region share of a FIXED total to SQL

SUM([Revenue]) / SUM({ FIXED : SUM([Revenue]) }) divides each region's revenue by the grand total, so the regions add up to 100%. In SQL: sum(Revenue) / sum(sum(Revenue)) OVER () over rows grouped by Region. Wrap the FIXED total in an aggregate such as SUM or MIN; it repeats on every mark, so either returns the grand total.

Updated · Checked on the xmetric engine

What is the syntax?

SUM([Revenue]) / SUM({ FIXED : SUM([Revenue]) })
numerator
SUM([Revenue]) per mark.
denominator
the FIXED grand total, wrapped in SUM, MIN or MAX.

Returns a fraction per mark: the region's part of the grand total.

What does it return, and what is the SQL?

Each example runs on the same 12 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.

What share of all revenue does each region make?

Tableau

SUM([Revenue]) / SUM({ FIXED : SUM([Revenue]) })

SQL (DuckDB)

SELECT
  Region,
  sum(Revenue) / sum(sum(Revenue)) OVER () AS result
FROM input
GROUP BY Region
ORDER BY Region

North makes 650 of 1,650: 39.4%. South 33.3%, West 27.3%.

RegionResult
North0.39
South0.33
West0.27

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

Does MIN around the FIXED total give the same share?

Tableau

SUM([Revenue]) / MIN({ FIXED : SUM([Revenue]) })

SQL (DuckDB)

SELECT
  Region,
  sum(Revenue) / sum(sum(Revenue)) OVER () AS result
FROM input
GROUP BY Region
ORDER BY Region

Yes. The total is the same on every row, so SUM, MIN and MAX of it agree per mark.

RegionResult
North0.39
South0.33
West0.27

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

Where does a straight translation go wrong?

Common mistake

Why is the share tiny when the total comes from a row-level window?

Writing the FIXED as sum(Revenue) OVER () on each line and then summing it per region counts 1,650 once per line: North divides by 8,250 and gets 7.9%.

Tableau

SUM([Revenue]) / SUM({ FIXED : SUM([Revenue]) })

Tempting SQL

SELECT Region, sum(Revenue) / sum(t) AS result
FROM (
  SELECT Region, Revenue, sum(Revenue) OVER () AS t
  FROM input
)
GROUP BY Region
ORDER BY Region

SQL that matches

SELECT
  Region,
  sum(Revenue) / sum(sum(Revenue)) OVER () AS result
FROM input
GROUP BY Region
ORDER BY Region
RegionTableauTempting SQLSQL that matches
North0.390.080.39
South0.330.070.33
West0.270.140.27

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
  Region,
  SUM(Revenue) / SUM(SUM(Revenue)) OVER () AS result
FROM input
GROUP BY Region
ORDER BY Region

Snowflake documentation

BigQuery

SELECT
  Region,
  SUM(Revenue) / SUM(SUM(Revenue)) OVER () AS result
FROM input
GROUP BY Region
ORDER BY Region

BigQuery documentation

What does your own Region share of fixed total formula return?

Edit the formula and run it on the 12 sample rows. Fields: [id], [Region], [Team], [Customer], [Invoice], [Revenue], [Date].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about Region share of fixed total?

Do filters change it?

Ordinary dimension filters on the Filters shelf do not: FIXED is computed before them. Add a filter to context (or filter the data source) to make it count only the rows that survive. In SQL, a context filter is a WHERE inside the subquery or window; an ordinary filter is a WHERE that does not reach it.

Why not a Percent of Total quick table calculation?

It gives the same numbers until you filter: a table calculation divides by what is left in the view, the FIXED total by the whole data source.

Will the shares still add up to 100% after a filter?

No, and that is often the point: with an ordinary filter on Region, the remaining regions still show their share of all revenue.

Where is this documented?