[p] AND [q] is true only when both are true. With a null side it is false if the other side is false, and null otherwise: the same three-valued logic as SQL. Inside IIF, the null rows return null, while a SQL CASE sends them to ELSE.
Updated · Checked on the xmetric engine
What is the syntax?
a AND b
a, b
booleans, or comparisons that return true, false or null.
Returns true, false or null (three-valued logic).
What does it return, and what is the SQL?
Each example runs on the same 8 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
Which rows have both p and q true?
Tableau
[p]AND[q]
SQL (DuckDB)
SELECT p AND q AS result
FROM input
ORDERBY id
Row 5 (null, true) is null; row 8 (false, null) is false.
p
q
Result
true
true
true
true
false
false
false
true
false
false
false
false
true
null
null
true
null
false
false
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does the CASE label null rows "no"?
IIF returns null when its test is null; CASE WHEN ... ELSE puts those rows in ELSE. Add a WHEN NOT (...) branch.
Tableau
IIF([p]AND[q], 'yes', 'no')
Tempting SQL
SELECTCASEWHEN p AND q THEN'yes'ELSE'no'ENDAS result
FROM input
ORDERBY id
SQL that matches
SELECTCASEWHEN p AND q THEN'yes'WHENNOT (p AND q) THEN'no'ENDAS result
FROM input
ORDERBY id
p
q
Tableau
Tempting SQL
SQL that matches
true
true
yes
yes
yes
true
false
no
no
no
false
true
no
no
no
false
false
no
no
no
true
null
no
null
null
no
null
true
null
no
null
false
no
no
no
✓ 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.