FLOOR(number) rounds down to the nearest integer of equal or lesser value: 7.9 becomes 7 and -2.5 becomes -3. DuckDB, Snowflake and BigQuery call it floor(). Don't swap in trunc() or INT(): they cut toward zero, which is the same for positive numbers and one too high for negative ones.
Updated · Checked on the xmetric engine
What is the syntax?
FLOOR(number)
number
a number or a numeric expression.
Returns an integer: the largest whole number not above the input. Null if the input is null.
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.
What is each value rounded down?
Tableau
FLOOR([Value])
SQL (DuckDB)
SELECTfloor(Value) AS result
FROM input
ORDERBY id
2.5 becomes 2, -2.5 becomes -3 and -0.4 becomes -1.
Value
Result
2.5
2
−2.5
−3
0.13
0
−0.4
−1
3.75
3
null
0
0
16
16
✓ The Tableau formula and the SQL return the same 8 rows.
Which bin of 4 does each quantity fall in?
Tableau
FLOOR([Qty]/4) *4
SQL (DuckDB)
SELECTfloor(Qty /4) *4AS result
FROM input
ORDERBY id
7 is in the bin starting at 4, -7 in the bin starting at -8, -1 in the bin starting at -4.
Qty
Result
7
4
−7
−8
10
8
9
8
2
0
4
4
−1
−4
0
0
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does trunc() round negative numbers the wrong way?
trunc drops the fraction, moving toward zero: -2.5 becomes -2 and -0.4 becomes 0. FLOOR moves down, to -3 and -1.
Tableau
FLOOR([Value])
Tempting SQL
SELECTtrunc(Value) AS result
FROM input
ORDERBY id
SQL that matches
SELECTfloor(Value) AS result
FROM input
ORDERBY id
Value
Tableau
Tempting SQL
SQL that matches
2.5
2
2
2
−2.5
−3
−2
−3
0.13
0
0
0
−0.4
−1
0
−1
3.75
3
3
3
null
null
null
0
0
0
0
16
16
16
16
✓ 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
SELECTFLOOR(Value) AS result
FROM input
ORDERBY id