RAWSQLAGG_DATETIME("MAX(%1)", [Shipped]) sends MAX(Shipped) to the database once per mark and reads a date and time back. In SQL, write the aggregate with a GROUP BY on the view's dimensions, and cast it to TIMESTAMP when the column is a plain date: Tableau shows it as midnight.
a string constant of SQL in your data source's dialect. %1, %2, ... are placeholders for the arguments that follow, numbered from 1.
argument, ...
fields or expressions. Tableau puts the first one where %1 is, the second where %2 is, and so on.
Returns one date and time per mark: the database's answer to an aggregate expression, grouped by the view's dimensions.
What does it return, and what is the SQL?
Each example runs on the same 6 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
When did each region last ship?
Tableau
RAWSQLAGG_DATETIME("MAX(%1)", [Shipped])
SQL (DuckDB)
SELECT Region, max(Shipped) AS result
FROM input
GROUPBY Region
ORDERBY Region
MAX skips West's unshipped line.
Region
Result
East
2026-02-1123:40
North
2026-03-1012:00
West
2026-03-0307:15
✓ The Tableau formula and the SQL return the same 3 rows.
When did each region's first order start?
Tableau
RAWSQLAGG_DATETIME("MIN(%1)", [Ordered])
SQL (DuckDB)
SELECT Region, CAST (min(Ordered) AS TIMESTAMP) AS result
FROM input
GROUPBY Region
ORDERBY Region
Order dates have no time, so each comes back as midnight.
Region
Result
East
2026-01-3000:00
North
2026-03-0900:00
West
2026-02-1400:00
✓ The Tableau formula and the SQL return the same 3 rows.
Where does a straight translation go wrong?
Common mistake
Why does the SQL return dates where Tableau shows midnight?
RAWSQLAGG_DATETIME reads the result as a date-time. min(Ordered) on a DATE column stays a DATE, so East shows 2026-01-30 in SQL and 2026-01-30 00:00:00 in Tableau.
Tableau
RAWSQLAGG_DATETIME("MIN(%1)", [Ordered])
Tempting SQL
SELECT Region, min(Ordered) AS result
FROM input
GROUPBY Region
ORDERBY Region
SQL that matches
SELECT Region, CAST (min(Ordered) AS TIMESTAMP) AS result
FROM input
GROUPBY Region
ORDERBY Region
Region
Tableau
Tempting SQL
SQL that matches
East
2026-01-3000:00
2026-01-30
2026-01-3000:00
North
2026-03-0900:00
2026-03-09
2026-03-0900:00
West
2026-02-1400:00
2026-02-14
2026-02-1400:00
✓ 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, MAX(Shipped) AS result
FROM input
GROUPBY Region
ORDERBY Region
The first argument after the SQL string. %2 is the second, and so on, whatever order the placeholders appear in the text. To translate a RAWSQL call, replace each %n with the column it points at and keep the rest of the text.
Does Tableau check the SQL inside RAWSQL?
No. Tableau passes the text to the database as it is, so a typo or a function your database lacks fails at query time, in the database. The text is also tied to that database's dialect: point the workbook at a different database and the same text can fail or mean something else.
What is the difference between RAWSQL and RAWSQLAGG?
RAWSQL_ functions are row-level: the expression runs once per row. RAWSQLAGG_ functions hold an aggregate such as SUM(%1) and run once per mark, grouped by the dimensions in the view. In SQL the first is a plain column expression; the second needs a GROUP BY on the view's dimensions.