Tableau function Level of detail

Tableau nested FIXED largest customer per region to SQL

{ FIXED [Region] : MAX({ FIXED [Customer] : SUM([Revenue]) }) } works inside out: the inner FIXED puts each customer's total revenue on every row, and the outer FIXED takes the MAX of those per region. In SQL: total per customer in a CTE, join it to the rows, then max() per Region. Because both levels are FIXED, the result ignores the view and its ordinary filters.

Updated · Checked on the xmetric engine

What is the syntax?

{ FIXED [Region] : MAX({ FIXED [Customer] : SUM([Revenue]) }) }
inner FIXED
one total per customer, attached to each of that customer's rows.
outer FIXED
the MAX of those row values per region.

Returns a number per row: the largest customer total in that row's region.

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 largest customer total in each region?

Tableau

{ FIXED [Region] : MAX({ FIXED [Customer] : SUM([Revenue]) }) }

SQL (DuckDB)

WITH c AS (
  SELECT Customer, sum(Revenue) AS total
  FROM input
  GROUP BY Customer
)
SELECT i.Region, max(c.total) AS result
FROM input i JOIN c USING (Customer)
GROUP BY i.Region
ORDER BY i.Region

North's customers total 260, 300 and 90, so 300; South's largest is Dahlia's 300, West's Holly's 450.

RegionResult
North300
South300
West450

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

What does each team row show?

Tableau

{ FIXED [Region] : MAX({ FIXED [Customer] : SUM([Revenue]) }) }

SQL (DuckDB)

WITH c AS (
  SELECT Customer, sum(Revenue) AS total
  FROM input
  GROUP BY Customer
), r AS (
  SELECT i.Region, max(c.total) AS v
  FROM input i JOIN c USING (Customer)
  GROUP BY i.Region
)
SELECT DISTINCT i.Region, i.Team, r.v AS result
FROM input i JOIN r USING (Region)
ORDER BY i.Region, i.Team

The outer FIXED ignores Team, so both teams of a region show the region's value.

RegionTeamResult
NorthCedar300
NorthPine300
SouthAsh300
SouthElm300
WestOak450

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

Where does a straight translation go wrong?

Common mistake

Why does max(Revenue) give a different number?

It returns the largest invoice line: 200 for South. The nested expression compares customer totals, so it adds each customer's lines first.

Tableau

{ FIXED [Region] : MAX({ FIXED [Customer] : SUM([Revenue]) }) }

Tempting SQL

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

SQL that matches

WITH c AS (
  SELECT Customer, sum(Revenue) AS total
  FROM input
  GROUP BY Customer
)
SELECT i.Region, max(c.total) AS result
FROM input i JOIN c USING (Customer)
GROUP BY i.Region
ORDER BY i.Region
RegionTableauTempting SQLSQL that matches
North300300300
South300200300
West450400450

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 c AS (
  SELECT Customer, SUM(Revenue) AS total
  FROM input
  GROUP BY Customer
)
SELECT i.Region, MAX(c.total) AS result
FROM input i JOIN c USING (Customer)
GROUP BY i.Region
ORDER BY i.Region

Snowflake documentation

BigQuery

WITH c AS (
  SELECT Customer, SUM(Revenue) AS total
  FROM input
  GROUP BY Customer
)
SELECT i.Region, MAX(c.total) AS result
FROM input i JOIN c USING (Customer)
GROUP BY i.Region
ORDER BY i.Region

BigQuery documentation

What does your own Nested largest customer per region 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 Nested largest customer per region?

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.

Is this the same as MAX({ INCLUDE [Customer] : SUM([Revenue]) })?

In a Region view, yes, here. The nested FIXED keeps the region value on every row and ignores the view; the INCLUDE version follows the view and dimension filters.

Can I flag the customer that holds the record?

Yes, row by row: { FIXED [Customer] : SUM([Revenue]) } = { FIXED [Region] : MAX({ FIXED [Customer] : SUM([Revenue]) }) } is true on that customer's rows.

Where is this documented?