[Field] IN (value1, value2, ...) returns true when the field matches any value in the list; the list can also be a set or a combined field. DuckDB, Snowflake and BigQuery write Field IN (...) the same way, and NOT [Field] IN (...) becomes Field NOT IN (...). Spelled out with comparisons, "not in" needs AND, not OR.
Updated · Checked on the xmetric engine
What is the syntax?
<expr1>IN<expr2>
expr1
a field or expression, row-level or aggregate (for example SUM([Cost])).
expr2
a list of literal values in parentheses, a set, or a combined field.
Returns a boolean: true if expr1 matches any value in expr2.
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 rows are in East or West?
Tableau
[Region]IN ('East', 'West')
SQL (DuckDB)
SELECT Region IN ('East', 'West') AS result
FROM input
ORDERBY id
Rows 5 and 6 are in North.
Region
Result
East
true
East
true
West
true
West
true
North
false
North
false
✓ The Tableau formula and the SQL return the same 6 rows.
SELECTCASEWHEN Region IN ('East', 'West') THEN'Coast'ELSE'Inland'ENDAS result
FROM input
ORDERBY id
North is Inland.
Region
Result
East
Coast
East
Coast
West
Coast
West
Coast
North
Inland
North
Inland
✓ The Tableau formula and the SQL return the same 6 rows.
Where does a straight translation go wrong?
Common mistake
Why does "not in" spelled with OR return true for everything?
Every region is either not East or not West, so Region <> 'East' OR Region <> 'West' is true on all six rows. NOT IN means not East and not West: only North.
Tableau
NOT[Region]IN ('East', 'West')
Tempting SQL
SELECT Region <>'East'OR Region <>'West'AS result
FROM input
ORDERBY id
SQL that matches
SELECT Region NOTIN ('East', 'West') AS result
FROM input
ORDERBY id
Region
Tableau
Tempting SQL
SQL that matches
East
false
true
false
East
false
true
false
West
false
true
false
West
false
true
false
North
true
true
true
North
true
true
true
✓ 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 IN ('East', 'West') AS result
FROM input
ORDERBY id