INT(expression) converts to an integer. For a number it drops the fraction toward zero: INT(-9.7) is -9 and INT(8/3) is 2. In DuckDB write CAST(trunc(x) AS BIGINT). A bare CAST(x AS INTEGER) rounds to the nearest integer, so -9.7 becomes -10. True becomes 1 and false 0.
Updated · Checked on the xmetric engine
What is the syntax?
INT(expression)
expression
a number, a numeric expression or a boolean.
Returns an integer. Null if the input 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.
What is each amount as a whole number?
Tableau
INT([Amount])
SQL (DuckDB)
SELECTCAST (trunc(Amount) AS BIGINT) AS result
FROM input
ORDERBY id
2.5 becomes 2, -9.7 becomes -9 and 1234567.891 becomes 1234567. The missing amount stays null.
Amount
Result
2.5
2
−9.7
−9
3
3
0.1
0
null
1,234,568
1,234,567
✓ The Tableau formula and the SQL return the same 6 rows.
How many whole halves are in each quantity?
Tableau
INT([Qty]/2)
SQL (DuckDB)
SELECTCAST (trunc(Qty /2) AS BIGINT) AS result
FROM input
ORDERBY id
7 / 2 is 3.5, so 3; -3 / 2 is -1.5, so -1.
Qty
Result
7
3
−3
−1
0
0
12
6
5
2
null
✓ The Tableau formula and the SQL return the same 6 rows.
How do I count flags as 1 and 0?
Tableau
INT([Flag])
SQL (DuckDB)
SELECTCAST (Flag AS INTEGER) AS result
FROM input
ORDERBY id
true becomes 1, false 0, unknown null.
Flag
Result
true
1
false
0
null
true
1
false
0
true
1
✓ The Tableau formula and the SQL return the same 6 rows.
Where does a straight translation go wrong?
Common mistake
Why does CAST(x AS INTEGER) give -10 for -9.7?
DuckDB rounds when it casts a decimal to an integer, so -9.7 becomes -10 and 1234567.891 becomes 1234568. Tableau's INT truncates toward zero. Truncate first.
Tableau
INT([Amount])
Tempting SQL
SELECTCAST (Amount AS INTEGER) AS result
FROM input
ORDERBY id
SQL that matches
SELECTCAST (trunc(Amount) AS BIGINT) AS result
FROM input
ORDERBY id
Amount
Tableau
Tempting SQL
SQL that matches
2.5
2
2
2
−9.7
−9
−10
−9
3
3
3
3
0.1
0
0
0
null
null
null
1,234,568
1,234,567
1,234,568
1,234,567
✓ 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
SELECTCAST (TRUNC(Amount) AS INTEGER) AS result
FROM input
ORDERBY id
It truncates toward zero for numbers: 2.5 becomes 2 and -9.7 becomes -9. Use ROUND to round, or FLOOR to always go down.
What does INT return for a boolean?
1 for true, 0 for false and null for unknown; in SQL CAST(Flag AS INTEGER).
What about strings?
Tableau's help says a string is first converted to a float and then rounded. This page leaves strings out; check the result on your data, and use INT(FLOAT([Code])) or ROUND when you need to be explicit.