Tableau function Level of detail

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, (
  SELECT sum(Revenue) AS total
  FROM input
) t
WHERE Region = 'North'
GROUP BY Team
ORDER BY Team

Only the North teams are left in the view, but both carry 1,650, the total of all three regions.

TeamResult
Cedar1,650
Pine1,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, (
  SELECT sum(Revenue) AS total
  FROM input
) t
WHERE Region = 'North'
GROUP BY Team
ORDER BY Team

Cedar's 500 over 1,650 is 30%; Pine's 150 is 9%.

TeamResult
Cedar0.3
Pine0.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, (
  SELECT sum(Revenue) AS total
  FROM f
) t
GROUP BY Team
ORDER BY Team

SQL that matches

SELECT Team, max(t.total) AS result
FROM input, (
  SELECT sum(Revenue) AS total
  FROM input
) t
WHERE Region = 'North'
GROUP BY Team
ORDER BY Team
TeamTableauTempting SQLSQL that matches
Cedar1,6506501,650
Pine1,6506501,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, (
  SELECT sum(Revenue) AS total
  FROM input
) t
WHERE Region = 'North'
GROUP BY Team
ORDER BY Team

Snowflake documentation

BigQuery

SELECT Team, sum(Revenue) / max(t.total) AS result
FROM input, (
  SELECT sum(Revenue) AS total
  FROM input
) t
WHERE Region = 'North'
GROUP BY Team
ORDER BY Team

BigQuery documentation

What does your own FIXED with a dimension filter 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 FIXED with a dimension filter?

How do I make the total follow the filter?

Add the filter to context (right-click it, Add to Context). Context filters run before FIXED. See Fixed total with context filter.

Which filters does FIXED respect?

Extract, data source and context filters, which all run before it. Dimension, measure and table calculation filters run after it.

Why is this useful?

It keeps the denominator of a share fixed: with North filtered, Cedar's 500 is 30% of all revenue, the number you want for a share of the company.

Where is this documented?