Tableau function Level of detail

Tableau FIXED grand total to SQL

{ FIXED : SUM([Revenue]) } has no dimensions, so it adds every row of the data source and repeats that total on each mark. Tableau also accepts the short form { SUM([Revenue]) }. In SQL it is an empty window over the grouped rows, sum(sum(Revenue)) OVER (), or a scalar subquery (SELECT sum(Revenue) FROM input).

Updated · Checked on the xmetric engine

What is the syntax?

{ FIXED : SUM([Revenue]) }
aggregate
an aggregate expression, such as SUM([Revenue]).

Returns a number per row: the total over the whole data source.

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 is the grand total on each region row?

Tableau

{ FIXED : SUM([Revenue]) }

SQL (DuckDB)

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

All three regions show 1,650.

RegionResult
North1,650
South1,650
West1,650

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

Where does a straight translation go wrong?

Common mistake

Why does a window on each line multiply the total?

sum(Revenue) OVER () on the raw rows puts 1,650 on every line; summing it per region counts it five times for North. Tableau repeats it once per mark.

Tableau

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

Tempting SQL

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

SQL that matches

SELECT Region, sum(sum(Revenue)) OVER () AS result
FROM input
GROUP BY Region
ORDER BY Region
RegionTableauTempting SQLSQL that matches
North1,6508,2501,650
South1,6508,2501,650
West1,6503,3001,650

The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.

Common mistake

Why does GROUP BY Region give region totals?

A FIXED with no dimensions ignores the view. The grouped sum is the region total (North 650); the FIXED value is 1,650 everywhere.

Tableau

{ FIXED : SUM([Revenue]) }

Tempting SQL

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

SQL that matches

SELECT Region, sum(sum(Revenue)) OVER () AS result
FROM input
GROUP BY Region
ORDER BY Region
RegionTableauTempting SQLSQL that matches
North1,6506501,650
South1,6505501,650
West1,6504501,650

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

Snowflake documentation

BigQuery

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

BigQuery documentation

What does your own Fixed grand 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 Fixed grand 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 wrap the FIXED total in SUM or MIN?

Tableau's help says a level of detail expression on a shelf is always wrapped in an aggregate. The grand total repeats on every mark, so SUM, MIN and MAX of it agree; writing one in the formula makes that explicit. See Region share of fixed total.

Is { SUM([Revenue]) } the same?

Yes. Tableau's help calls it a table-scoped expression, equivalent to FIXED with no dimensions.

Where is this documented?