SIZE() returns how many marks the current partition has. With Region and Month on the view and Compute Using Month, each region has four marks, so every row gets 4. In SQL it is count(*) OVER (PARTITION BY Region) on the grouped marks, not on the raw rows.
Updated · Checked on the xmetric engine
What is the syntax?
SIZE()
Returns an integer: the number of marks in the current partition.
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 many months does each region have?
Tableau
SIZE()
Compute using Month, restarting for each Region
SQL (DuckDB)
SELECT Region,
Month,
count(*) OVER (PARTITIONBY Region) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Compute using Month: four marks per region, including West's month with no sales.
Region
Month
Result
East
1
4
East
2
4
East
3
4
East
4
4
West
1
4
West
2
4
West
3
4
West
4
4
✓ The Tableau formula and the SQL return the same 8 rows.
How many regions are there in each month?
Tableau
SIZE()
Compute using Region, restarting for each Month
SQL (DuckDB)
SELECT Region,
Month,
count(*) OVER (PARTITIONBY Month) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Compute using Region: the partition is now a month, holding two marks.
Region
Month
Result
East
1
2
East
2
2
East
3
2
East
4
2
West
1
2
West
2
2
West
3
2
West
4
2
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does the SQL give East five instead of four?
Counting before grouping counts source rows. East has two rows in month 2, so a window over the raw table sees five rows; Tableau sees four marks.
Tableau
SIZE()
Compute using Month, restarting for each Region
Tempting SQL
SELECTDISTINCT Region,
Month,
count(*) OVER (PARTITIONBY Region) AS result
FROM input
ORDERBY Region, Month
SQL that matches
SELECT Region,
Month,
count(*) OVER (PARTITIONBY Region) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Region
Month
Tableau
Tempting SQL
SQL that matches
East
1
4
5
4
East
2
4
5
4
East
3
4
5
4
East
4
4
5
4
West
1
4
4
4
West
2
4
4
4
West
3
4
4
4
West
4
4
4
4
✓ 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,
COUNT(*) OVER (PARTITIONBY Region) AS result
FROM input
GROUPBY Region, Month
ORDERBY Region, Month
Tableau computes the table calculation on marks, one per Region and Month in this view. The GROUP BY builds those marks; East has two rows in month 2 (80 and 40), and they become one mark of 120.
Does SIZE() skip null measures?
No. It counts marks, whatever their values. West month 3 has no sales and is still one of West's four marks. To count non-null values, use WINDOW_COUNT.
How do I flag regions with fewer than four months of data?
SIZE() < 4 in Tableau; in SQL, count(*) OVER (PARTITION BY Region) < 4 in the grouped query.