RUNNING_MIN(SUM([Sales])) returns the smallest value from the first mark in the partition to the current one. In SQL that is min(sum(Sales)) OVER (PARTITION BY Region ORDER BY Month). The inner sum matters: the window runs over marks, not rows.
Updated · Checked on the xmetric engine
What is the syntax?
RUNNING_MIN(expression)
expression
an aggregate, such as SUM([Sales]). Compute Using sets which marks it runs along and where it restarts.
Returns a number: the minimum of the expression from the first mark in the partition to the current mark.
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 get the lowest month so far, per region?
Tableau
RUNNING_MIN(SUM([Sales]))
Compute using Month, restarting for each Region
SQL (DuckDB)
SELECT Region,
Month,
min(sum(Sales)) OVER (PARTITIONBY Region ORDERBY Month) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Compute using Month: East holds 100 until month 3 drops it to 60. West stays at 50; the null month changes nothing.
Region
Month
Result
East
1
100
East
2
100
East
3
60
East
4
60
West
1
50
West
2
50
West
3
50
West
4
50
✓ The Tableau formula and the SQL return the same 8 rows.
How do I run it across regions, within each month?
Tableau
RUNNING_MIN(SUM([Sales]))
Compute using Region, restarting for each Month
SQL (DuckDB)
SELECT Region,
Month,
min(sum(Sales)) OVER (PARTITIONBY Month ORDERBY Region) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Compute using Region: the same formula now runs East then West inside each month.
Region
Month
Result
East
1
100
East
2
120
East
3
60
East
4
120
West
1
50
West
2
70
West
3
60
West
4
90
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does the SQL drop to 40 in East's month 2?
min(min(Sales)) takes the smallest row inside each mark first, and East month 2 has a row of 40. RUNNING_MIN(SUM) works on the mark total, 120, so the running low stays at 100.
Tableau
RUNNING_MIN(SUM([Sales]))
Compute using Month, restarting for each Region
Tempting SQL
SELECT Region,
Month,
min(min(Sales)) OVER (PARTITIONBY Region ORDERBY Month) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
SQL that matches
SELECT Region,
Month,
min(sum(Sales)) OVER (PARTITIONBY Region ORDERBY Month) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Region
Month
Tableau
Tempting SQL
SQL that matches
East
1
100
100
100
East
2
100
40
100
East
3
60
40
60
East
4
60
40
60
West
1
50
50
50
West
2
50
50
50
West
3
50
50
50
West
4
50
50
50
✓ 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,
MIN(SUM(Sales)) OVER (PARTITIONBY Region ORDERBY Month) 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.
What happens to the month with no sales?
It is skipped: the running result carries the value from the months before it. West month 3 has no sales, so its running value equals month 2's. SQL aggregate windows skip nulls the same way.
Does a null month reset the minimum to zero?
No, a null is skipped. It only becomes zero if you wrap the expression in ZN(); in SQL, coalesce(sum(Sales), 0) does the same.
How do I restart it every year?
Put the year in the partition: in Tableau, compute using Month only, with Year on the view; in SQL, PARTITION BY Region, Year ORDER BY Month.