Tableau function Level of detail

Tableau EXCLUDE all view dimensions to SQL

{ EXCLUDE [Region], [Team] : SUM([Revenue]) } in a Region by Team view removes both dimensions, so every mark shows the grand total. In SQL that is an empty window over the grouped rows: sum(sum(Revenue)) OVER ().

Updated · Checked on the xmetric engine

What is the syntax?

{ EXCLUDE [Region], [Team] : SUM([Revenue]) }
dimensions
every dimension in the view.
aggregate
an aggregate expression, such as SUM([Revenue]).

Returns a number per mark: the aggregate over everything the view shows, repeated on each 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 is the grand total on every team row?

Tableau

{ EXCLUDE [Region], [Team] : SUM([Revenue]) }

SQL (DuckDB)

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

All five team rows show 1,650, the sum of every invoice line.

RegionTeamResult
NorthCedar1,650
NorthPine1,650
SouthAsh1,650
SouthElm1,650
WestOak1,650

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

What share of all revenue does each team make?

Tableau

SUM([Revenue]) / SUM({ EXCLUDE [Region], [Team] : SUM([Revenue]) })

SQL (DuckDB)

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

Cedar makes 500 of 1,650: 30.3%.

RegionTeamResult
NorthCedar0.3
NorthPine0.09
SouthAsh0.15
SouthElm0.18
WestOak0.27

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

Where does a straight translation go wrong?

Common mistake

Why does GROUP BY Region, Team give team totals?

Grouping by the view keeps both dimensions; EXCLUDE removes both. Cedar shows 1,650, not 500.

Tableau

{ EXCLUDE [Region], [Team] : SUM([Revenue]) }

Tempting SQL

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

SQL that matches

SELECT Region, Team, sum(sum(Revenue)) OVER () AS result
FROM input
GROUP BY Region, Team
ORDER BY Region, Team
RegionTeamTableauTempting SQLSQL that matches
NorthCedar1,6505001,650
NorthPine1,6501501,650
SouthAsh1,6502501,650
SouthElm1,6503001,650
WestOak1,6504501,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 a window on each line multiply the total?

sum(Revenue) OVER () puts 1,650 on every invoice line; summing per team then adds it once per line. Tableau repeats the value once per mark.

Tableau

SUM({ EXCLUDE [Region], [Team] : SUM([Revenue]) })

Tempting SQL

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

SQL that matches

SELECT Region, Team, sum(sum(Revenue)) OVER () AS result
FROM input
GROUP BY Region, Team
ORDER BY Region, Team
RegionTeamTableauTempting SQLSQL that matches
NorthCedar1,6504,9501,650
NorthPine1,6503,3001,650
SouthAsh1,6504,9501,650
SouthElm1,6503,3001,650
WestOak1,6503,3001,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, Team, SUM(SUM(Revenue)) OVER () AS result
FROM input
GROUP BY Region, Team
ORDER BY Region, Team

Snowflake documentation

BigQuery

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

BigQuery documentation

What does your own Exclude all view dimensions 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 Exclude all view dimensions?

Do filters change it?

Yes. INCLUDE and EXCLUDE are computed after dimension filters, so filtering out a team removes its revenue from the region total too. That is the main practical difference from a FIXED region total.

Is this the same as { FIXED : SUM([Revenue]) }?

The numbers match until you filter. EXCLUDE runs after dimension filters, FIXED before them. See Fixed grand total.

Is this the same as the TOTAL table calculation?

Close: TOTAL(SUM([Revenue])) computed across the whole table returns the same 1,650, but as a table calculation it also sees table-calculation filters.

Where is this documented?