TOTAL(SUM([Sales])) returns the sum of sales over every mark in the partition, repeated on each mark. In SQL that is sum(sum(Sales)) OVER (PARTITION BY Region): no ORDER BY, so the window is the whole partition. Unlike WINDOW_SUM, TOTAL recomputes the aggregate from the underlying rows, which matters for averages and distinct counts.
Updated · Checked on the xmetric engine
What is the syntax?
TOTAL(expression)
expression
an aggregate, such as SUM([Sales]).
Returns the aggregate of the expression over the whole partition, on every mark of it.
What does it return, and what is the SQL?
Each example runs on the same 9 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
How do I show each region's total on every month?
Tableau
TOTAL(SUM([Sales]))
Compute using Month, restarting for each Region
SQL (DuckDB)
SELECT Region,
Month,
sum(sum(Sales)) OVER (PARTITIONBY Region) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Compute using Month: every East mark shows 400, every West mark 210.
Region
Month
Result
East
1
400
East
2
400
East
3
400
East
4
400
West
1
210
West
2
210
West
3
210
West
4
210
✓ The Tableau formula and the SQL return the same 8 rows.
How do I show each month's total across regions?
Tableau
TOTAL(SUM([Sales]))
Compute using Region, restarting for each Month
SQL (DuckDB)
SELECT Region,
Month,
sum(sum(Sales)) OVER (PARTITIONBY Month) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Compute using Region: the partition is now the month, so month 1 shows 100 + 50 = 150 on both regions.
Region
Month
Result
East
1
150
East
2
190
East
3
60
East
4
210
West
1
150
West
2
190
West
3
60
West
4
210
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why is every row the grand total?
An empty OVER () sums all eight marks, 610. Compute Using Month partitions by Region, so TOTAL is 400 for East and 210 for West.
Tableau
TOTAL(SUM([Sales]))
Compute using Month, restarting for each Region
Tempting SQL
SELECT Region, Month, sum(sum(Sales)) OVER () AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
SQL that matches
SELECT Region,
Month,
sum(sum(Sales)) OVER (PARTITIONBY Region) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Region
Month
Tableau
Tempting SQL
SQL that matches
East
1
400
610
400
East
2
400
610
400
East
3
400
610
400
East
4
400
610
400
West
1
210
610
210
West
2
210
610
210
West
3
210
610
210
West
4
210
610
210
✓ 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,
Month,
SUM(SUM(Sales)) OVER (PARTITIONBY Region) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
A table calculation runs on the marks in the view, so its argument must be an aggregate. A bare field such as [Sales] raises an error; see All fields must be aggregate or constant.
How is TOTAL different from WINDOW_SUM?
For SUM they agree. For AVG, Tableau documents that TOTAL(AVG([Sales])) is the average of the underlying rows (East: 400 / 5 rows = 80), while WINDOW_AVG(AVG([Sales])) averages the marks. In SQL the row-level version is sum(sum(Sales)) OVER (PARTITION BY Region) / sum(count(Sales)) OVER (PARTITION BY Region).
What happens to a null mark?
It adds nothing. West's total is 50 + 70 + 90 = 210, and West month 3 still shows 210.