Tableau function Pass-through (RAWSQL)

Tableau RAWSQLAGG_DATE to SQL

RAWSQLAGG_DATE("MIN(%1)", [Ordered]) sends MIN(Ordered) to the database once per mark and reads the result as a date. In SQL, write the aggregate with a GROUP BY on the view's dimensions, and cast it to DATE when the column holds times: the date-time a MAX finds comes back without its time.

Updated · Checked on the xmetric engine

What is the syntax?

RAWSQLAGG_DATE("sql_expression", [argument1], [argument2], ...)
sql_expression
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 per mark (no time part): 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 was each region's first order?

Tableau

RAWSQLAGG_DATE("MIN(%1)", [Ordered])

SQL (DuckDB)

SELECT Region, min(Ordered) AS result
FROM input
GROUP BY Region
ORDER BY Region

Ordered is already a date, so no cast is needed.

RegionResult
East2026-01-30
North2026-03-09
West2026-02-14

The Tableau formula and the SQL return the same 3 rows.

On which day did each region last ship?

Tableau

RAWSQLAGG_DATE("MAX(%1)", [Shipped])

SQL (DuckDB)

SELECT Region, CAST (max(Shipped) AS DATE) AS result
FROM input
GROUP BY Region
ORDER BY Region

West's unshipped line is ignored by MAX, so West returns 3 March.

RegionResult
East2026-02-11
North2026-03-10
West2026-03-03

The Tableau formula and the SQL return the same 3 rows.

Where does a straight translation go wrong?

Common mistake

Why does the SQL keep the shipping time?

RAWSQLAGG_DATE returns a date. max(Shipped) alone returns the full timestamp, 23:40 on 11 February for East, which then fails to match a date or join to a calendar.

Tableau

RAWSQLAGG_DATE("MAX(%1)", [Shipped])

Tempting SQL

SELECT Region, max(Shipped) AS result
FROM input
GROUP BY Region
ORDER BY Region

SQL that matches

SELECT Region, CAST (max(Shipped) AS DATE) AS result
FROM input
GROUP BY Region
ORDER BY Region
RegionTableauTempting SQLSQL that matches
East2026-02-112026-02-11 23:402026-02-11
North2026-03-102026-03-10 12:002026-03-10
West2026-03-032026-03-03 07:152026-03-03

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, CAST (MAX(Shipped) AS DATE) AS result
FROM input
GROUP BY Region
ORDER BY Region

Snowflake documentation

BigQuery

SELECT Region, DATE(MAX(Shipped)) AS result
FROM input
GROUP BY Region
ORDER BY Region

BigQuery documentation

What does your own RAWSQLAGG_DATE formula return?

Edit the formula and run it on the 6 sample rows. Fields: [id], [Region], [Product], [Units], [Boxes], [Sales], [Ordered], [Shipped].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about RAWSQLAGG_DATE?

What does %1 stand for?

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.

Where is this documented?