Tableau function Level of detail

Tableau EXCLUDE team region total to SQL

{ EXCLUDE [Team] : SUM([Revenue]) } computes the sum at the view's level of detail minus Team. In a Region by Team view that is the region total, repeated on each team row. In SQL it is a window over the grouped rows that partitions by the view dimensions you keep: sum(sum(Revenue)) OVER (PARTITION BY Region).

Updated · Checked on the xmetric engine

What is the syntax?

{ EXCLUDE [Team] : SUM([Revenue]) }
dimensions
the view dimensions to leave out; any not in the view are ignored.
aggregate
an aggregate expression, such as SUM([Revenue]).

Returns a number per mark: the aggregate over the view's dimensions minus the excluded ones.

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 region total on each team row?

Tableau

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

SQL (DuckDB)

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

Cedar and Pine both show North's 650: EXCLUDE removes Team, so the sum runs over Region only.

RegionTeamResult
NorthCedar650
NorthPine650
SouthAsh550
SouthElm550
WestOak450

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

What does it return when Team is not in the view?

Tableau

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

SQL (DuckDB)

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

Excluding a dimension the view doesn't have changes nothing: it is the plain region total.

RegionResult
North650
South550
West450

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

Where does a straight translation go wrong?

Common mistake

Why does GROUP BY Region, Team give team totals?

The grouped query keeps Team in the grain. EXCLUDE takes it out, so every team row shows its region's total: Cedar 650, not 500.

Tableau

{ EXCLUDE [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 (PARTITION BY Region) AS result
FROM input
GROUP BY Region, Team
ORDER BY Region, Team
RegionTeamTableauTempting SQLSQL that matches
NorthCedar650500650
NorthPine650150650
SouthAsh550250550
SouthElm550300550
WestOak450450450

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 (PARTITION BY Region) AS result
FROM input
GROUP BY Region, Team
ORDER BY Region, Team

Snowflake documentation

BigQuery

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

BigQuery documentation

What does your own Region total excluding team 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 total excluding team?

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.

Can EXCLUDE be used on a row-level calculation?

No. Tableau's help says EXCLUDE can't be used where there are no view dimensions to omit, such as a row-level expression.

How do I show each team's share of its region?

Divide by it: SUM([Revenue]) / SUM({ EXCLUDE [Team] : SUM([Revenue]) }). See Team share within region.

Where is this documented?