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%.
| Region | Result |
|---|
| East | 0.24 |
| South | 0.3 |
| West | 0.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%.
| Region | Result |
|---|
| East | 1 |
| South | 1 |
| West | 1 |
✓ 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.
| Region | Category | Result |
|---|
| East | Furniture | 1 |
| South | Furniture | 1 |
| West | Furniture | 1 |
✓ The Tableau formula and the SQL return the same 3 rows.