EXCLUDE is computed after dimension filters, so { EXCLUDE [Team] : SUM([Revenue]) } adds only the rows the filter keeps. With Team filtered to Cedar and Elm, North's region total is Cedar's 500, not 650. In SQL, filter first, then take the window over the filtered rows.
Updated · Checked on the xmetric engine
What is the syntax?
{ EXCLUDE [Team] : SUM([Revenue]) }
dimensions
the view dimensions to leave out, here [Team].
aggregate
an aggregate such as SUM([Revenue]).
Returns the aggregate at the view's level without the excluded dimension, over the rows the filters keep.
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 region total return with Team filtered to Cedar and Elm?
Tableau
{ EXCLUDE [Team] : SUM([Revenue]) }
Filter Team = Cedar, Elm, as a dimension filter
SQL (DuckDB)
WITH f AS (
SELECT*FROM input
WHERE Team IN ('Cedar', 'Elm')
)
SELECT Region,
Team,
sum(sum(Revenue)) OVER (PARTITIONBY Region) AS result
FROM f
GROUPBY Region, Team
ORDERBY Region, Team
North's total is Cedar's 500 and South's is Elm's 300: the filtered-out teams Pine and Ash are not counted.
Region
Team
Result
North
Cedar
500
South
Elm
300
✓ The Tableau formula and the SQL return the same 2 rows.
Where does a straight translation go wrong?
Common mistake
Why does a region-total subquery over the whole table give 650?
A per-region subquery over input behaves like FIXED: it reads every team. EXCLUDE only sees what the dimension filter kept, so filter before building the total.
Tableau
{ EXCLUDE [Team] : SUM([Revenue]) }
Filter Team = Cedar, Elm, as a dimension filter
Tempting SQL
WITH totals AS (
SELECT Region, sum(Revenue) AS total
FROM input
GROUPBY Region
)
SELECT i.Region, i.Team, max(totals.total) AS result
FROM input i JOIN totals USING (Region)
WHERE i.Team IN ('Cedar', 'Elm')
GROUPBY i.Region, i.Team
ORDERBY i.Region, i.Team
SQL that matches
WITH f AS (
SELECT*FROM input
WHERE Team IN ('Cedar', 'Elm')
)
SELECT Region,
Team,
sum(sum(Revenue)) OVER (PARTITIONBY Region) AS result
FROM f
GROUPBY Region, Team
ORDERBY Region, Team
Region
Team
Tableau
Tempting SQL
SQL that matches
North
Cedar
500
650
500
South
Elm
300
550
300
✓ 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
WITH f AS (
SELECT*FROM input
WHERE Team IN ('Cedar', 'Elm')
)
SELECT Region,
Team,
sum(sum(Revenue)) OVER (PARTITIONBY Region) AS result
FROM f
GROUPBY Region, Team
ORDERBY Region, Team
WITH f AS (
SELECT*FROM input
WHERE Team IN ('Cedar', 'Elm')
)
SELECT Region,
Team,
sum(sum(Revenue)) OVER (PARTITIONBY Region) AS result
FROM f
GROUPBY Region, Team
ORDERBY Region, Team