RAWSQL_BOOL("%1 > 100", [Sales]) hands the text Sales > 100 to the database, row by row, and reads the answer as true or false. In SQL you write the expression itself: Sales > 100. A null Sales gives null, not false, which matters as soon as the result feeds an IIF.
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 boolean per row: whatever the database returns for the expression. 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.
Which lines sold more than 100?
Tableau
RAWSQL_BOOL("%1 > 100", [Sales])
SQL (DuckDB)
SELECT Sales >100AS result
FROM input
ORDERBY id
%1 becomes Sales. Lines 2 and 6 have no sales, so the comparison is null there, not false.
Sales
Result
241
true
null
85
false
410
true
60.25
false
null
✓ The Tableau formula and the SQL return the same 6 rows.
Which lines filled every box exactly once?
Tableau
RAWSQL_BOOL("%1 = %2", [Units], [Boxes])
SQL (DuckDB)
SELECT Units = Boxes AS result
FROM input
ORDERBY id
%1 is the first argument (Units), %2 the second (Boxes). Line 5 has no box count, so it returns null.
Units
Boxes
Result
12
4
false
7
2
false
5
1
false
9
3
false
3
null
4
4
true
✓ The Tableau formula and the SQL return the same 6 rows.
Where does a straight translation go wrong?
Common mistake
Why does a CASE WHEN turn the null rows into "small"?
Tableau's IIF returns null when its test is null, so lines 2 and 6 stay null. CASE WHEN ... ELSE sends a null test to the ELSE branch. Give the null case its own branch, or test both outcomes explicitly.
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.