Tableau FIXED total with an ordinary filter, in SQL
An ordinary dimension filter runs after FIXED, so { FIXED : SUM([Revenue]) } still adds every region: with Region filtered to North, each North team shows 1,650, not North's 650. In SQL the filter is a WHERE on the outer query only; the subquery that builds the total reads the whole table.
Updated · Checked on the xmetric engine
What is the syntax?
{ FIXED : SUM([Revenue]) }
dimensions
none here, so one value for the whole table.
aggregate
an aggregate such as SUM([Revenue]).
Returns the total over every row that passed the context and data source filters, the same on every mark.
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 does the FIXED total return with Region filtered to North?
Tableau
{ FIXED : SUM([Revenue]) }
Filter Region = North, as a dimension filter
SQL (DuckDB)
SELECT Team, max(t.total) AS result
FROM input, (
SELECTsum(Revenue) AS total
FROM input
) t
WHERE Region ='North'GROUPBY Team
ORDERBY Team
Only the North teams are left in the view, but both carry 1,650, the total of all three regions.
Team
Result
Cedar
1,650
Pine
1,650
✓ The Tableau formula and the SQL return the same 2 rows.
What share of all revenue does each North team have?
Tableau
SUM([Revenue]) /MIN({ FIXED : SUM([Revenue]) })
Filter Region = North, as a dimension filter
SQL (DuckDB)
SELECT Team, sum(Revenue) /max(t.total) AS result
FROM input, (
SELECTsum(Revenue) AS total
FROM input
) t
WHERE Region ='North'GROUPBY Team
ORDERBY Team
Cedar's 500 over 1,650 is 30%; Pine's 150 is 9%.
Team
Result
Cedar
0.3
Pine
0.09
✓ The Tableau formula and the SQL return the same 2 rows.
Where does a straight translation go wrong?
Common mistake
Why does filtering the table first give North's total instead?
The natural SQL filters once and computes everything from the filtered rows. That is a context filter, and it makes the total 650. An ordinary Tableau filter does not reach the FIXED total.
Tableau
{ FIXED : SUM([Revenue]) }
Filter Region = North, as a dimension filter
Tempting SQL
WITH f AS (
SELECT*FROM input
WHERE Region ='North')
SELECT Team, max(t.total) AS result
FROM f, (
SELECTsum(Revenue) AS total
FROM f
) t
GROUPBY Team
ORDERBY Team
SQL that matches
SELECT Team, max(t.total) AS result
FROM input, (
SELECTsum(Revenue) AS total
FROM input
) t
WHERE Region ='North'GROUPBY Team
ORDERBY Team
Team
Tableau
Tempting SQL
SQL that matches
Cedar
1,650
650
1,650
Pine
1,650
650
1,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 Team, sum(Revenue) /max(t.total) AS result
FROM input, (
SELECTsum(Revenue) AS total
FROM input
) t
WHERE Region ='North'GROUPBY Team
ORDERBY Team
SELECT Team, sum(Revenue) /max(t.total) AS result
FROM input, (
SELECTsum(Revenue) AS total
FROM input
) t
WHERE Region ='North'GROUPBY Team
ORDERBY Team