Tableau function Level of detail

Why your FIXED LOD ignores the filter

Tableau computes {FIXED ...} before ordinary dimension filters, so a Category filter removes rows from the view but not from the FIXED total. A context filter runs before FIXED, so the total shrinks with it. In SQL, a dimension filter is a WHERE on the outer query only; a context filter is a WHERE inside the subquery that builds the total too.

Updated · Checked on the xmetric engine

What is the syntax?

{ FIXED [dimension 1], [dimension 2] : aggregate }
dimensions
the fields to group by. None ({ FIXED : SUM([Sales]) }) means one value for the whole table.
aggregate
an aggregate such as SUM([Sales]) or COUNTD([Customer]).

Returns the aggregate at the listed dimensions, whatever dimensions the view has, computed before dimension filters.

What does it return, and what is the SQL?

Each example runs on the same 8 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.

What does the share return with an ordinary Category filter?

Tableau

SUM([Sales]) / MIN({FIXED [Region] : SUM([Sales])})

Filter Category = Furniture, as a dimension filter

SQL (DuckDB)

WITH totals AS (
  SELECT Region, sum(Sales) AS total
  FROM input
  GROUP BY Region
)
SELECT i.Region, sum(i.Sales) / min(totals.total) AS result
FROM input i JOIN totals USING (Region)
WHERE i.Category = 'Furniture'
GROUP BY i.Region
ORDER BY i.Region

The totals subquery has no WHERE, so it keeps every category. East's Furniture is 120 of 500, 24%.

RegionResult
East0.24
South0.3
West0.5

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

What does it return when Category is a context filter?

Tableau

SUM([Sales]) / MIN({FIXED [Region] : SUM([Sales])})

Filter Category = Furniture, as a context filter

SQL (DuckDB)

WITH f AS (
  SELECT *
  FROM input
  WHERE Category = 'Furniture'
), totals AS (
  SELECT Region, sum(Sales) AS total
  FROM f
  GROUP BY Region
)
SELECT f.Region, sum(f.Sales) / min(totals.total) AS result
FROM f JOIN totals USING (Region)
GROUP BY f.Region
ORDER BY f.Region

The WHERE moved up into the rows both queries read, so each region's total is its Furniture sales and every share is 100%.

RegionResult
East1
South1
West1

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

Why does an EXCLUDE version follow the filter?

Tableau

SUM([Sales]) / MIN({EXCLUDE [Category] : SUM([Sales])})

Filter Category = Furniture, as a dimension filter

SQL (DuckDB)

WITH f AS (
  SELECT *
  FROM input
  WHERE Category = 'Furniture'
), totals AS (
  SELECT Region, sum(Sales) AS total
  FROM f
  GROUP BY Region
)
SELECT
  f.Region,
  f.Category,
  sum(f.Sales) / min(totals.total) AS result
FROM f JOIN totals USING (Region)
GROUP BY f.Region, f.Category
ORDER BY f.Region

EXCLUDE runs after dimension filters, so it only sees Furniture. Use FIXED when the total must ignore the filter.

RegionCategoryResult
EastFurniture1
SouthFurniture1
WestFurniture1

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

Where does a straight translation go wrong?

Common mistake

Why does filtering first in SQL give 100% everywhere?

The natural SQL filters the table once and builds everything from it. That is a context filter. Tableau's ordinary filter leaves the FIXED total untouched, so the WHERE belongs only on the outer query.

Tableau

SUM([Sales]) / MIN({FIXED [Region] : SUM([Sales])})

Filter Category = Furniture, as a dimension filter

Tempting SQL

WITH f AS (
  SELECT *
  FROM input
  WHERE Category = 'Furniture'
), totals AS (
  SELECT Region, sum(Sales) AS total
  FROM f
  GROUP BY Region
)
SELECT f.Region, sum(f.Sales) / min(totals.total) AS result
FROM f JOIN totals USING (Region)
GROUP BY f.Region
ORDER BY f.Region

SQL that matches

WITH totals AS (
  SELECT Region, sum(Sales) AS total
  FROM input
  GROUP BY Region
)
SELECT i.Region, sum(i.Sales) / min(totals.total) AS result
FROM input i JOIN totals USING (Region)
WHERE i.Category = 'Furniture'
GROUP BY i.Region
ORDER BY i.Region
RegionTableauTempting SQLSQL that matches
East0.2410.24
South0.310.3
West0.510.5

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 totals AS (
  SELECT Region, SUM(Sales) AS total
  FROM input
  GROUP BY Region
)
SELECT i.Region, SUM(i.Sales) / MIN(totals.total) AS result
FROM input i JOIN totals USING (Region)
WHERE i.Category = 'Furniture'
GROUP BY i.Region
ORDER BY i.Region

Snowflake documentation

BigQuery

WITH totals AS (
  SELECT Region, SUM(Sales) AS total
  FROM input
  GROUP BY Region
)
SELECT i.Region, SUM(i.Sales) / MIN(totals.total) AS result
FROM input AS i JOIN totals USING (Region)
WHERE i.Category = 'Furniture'
GROUP BY i.Region
ORDER BY i.Region

BigQuery documentation

What does your own FIXED formula return?

Edit the formula and run it on the 8 sample rows. Fields: [id], [Region], [Category], [Sales].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about FIXED?

How do I make a FIXED LOD respect a filter?

Right-click the filter on the Filters shelf and choose Add to Context. Context filters run before FIXED expressions, so the total is built only from the rows that pass. The pill turns grey.

Do INCLUDE and EXCLUDE ignore filters too?

No. They're computed after dimension filters, so they already see only the filtered rows. Only FIXED, and only for dimension filters, runs first.

Which filters does a FIXED LOD always respect?

Extract filters, data source filters and context filters. They all run before FIXED. Measure filters and table calculation filters run after it.

Why would I want FIXED to ignore the filter?

For a share of total. With Category filtered to Furniture, Furniture's sales over the unfiltered region total is the number you usually want, 24% for East.

Where is this documented?