Tableau function Pass-through (RAWSQL)

Tableau RAWSQL_DATETIME to SQL

RAWSQL_DATETIME("%1", [Shipped]) sends the expression to the database and reads the answer as a date and time. In SQL, write the expression with the column in place of %1 and cast it to TIMESTAMP: a plain date passed through RAWSQL_DATETIME comes back as midnight on that day.

Updated · Checked on the xmetric engine

What is the syntax?

RAWSQL_DATETIME("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 a date and time per row: the database's answer read as a date-time. Null when the expression is null.

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 exactly did each line ship?

Tableau

RAWSQL_DATETIME("%1", [Shipped])

SQL (DuckDB)

SELECT Shipped AS result
FROM input
ORDER BY id

Shipped is already a date-time, so nothing changes. Line 4 has not shipped and stays null.

ShippedResult
2026-01-31 18:202026-01-31 18:20
2026-02-05 09:052026-02-05 09:05
2026-02-11 23:402026-02-11 23:40
null
2026-03-03 07:152026-03-03 07:15
2026-03-10 12:002026-03-10 12:00

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

What does an order date look like as a date-time?

Tableau

RAWSQL_DATETIME("%1", [Ordered])

SQL (DuckDB)

SELECT CAST (Ordered AS TIMESTAMP) AS result
FROM input
ORDER BY id

Each order date becomes midnight at the start of that day.

OrderedResult
2026-01-302026-01-30 00:00
2026-02-032026-02-03 00:00
2026-02-112026-02-11 00:00
2026-02-142026-02-14 00:00
2026-03-012026-03-01 00:00
2026-03-092026-03-09 00:00

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

Where does a straight translation go wrong?

Common mistake

Why does the SQL show dates where Tableau shows midnight?

RAWSQL_DATETIME reads the result as a date-time, so 30 January becomes 30 January 00:00:00. Without the cast the SQL returns a DATE, which compares and formats differently.

Tableau

RAWSQL_DATETIME("%1", [Ordered])

Tempting SQL

SELECT Ordered AS result
FROM input
ORDER BY id

SQL that matches

SELECT CAST (Ordered AS TIMESTAMP) AS result
FROM input
ORDER BY id
OrderedTableauTempting SQLSQL that matches
2026-01-302026-01-30 00:002026-01-302026-01-30 00:00
2026-02-032026-02-03 00:002026-02-032026-02-03 00:00
2026-02-112026-02-11 00:002026-02-112026-02-11 00:00
2026-02-142026-02-14 00:002026-02-142026-02-14 00:00
2026-03-012026-03-01 00:002026-03-012026-03-01 00:00
2026-03-092026-03-09 00:002026-03-092026-03-09 00: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 CAST (Ordered AS TIMESTAMP_NTZ) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT CAST (Ordered AS DATETIME) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own RAWSQL_DATETIME 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 RAWSQL_DATETIME?

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.

Where is this documented?