Tableau function Number

Tableau FLOOR to SQL

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)

SELECT floor(Value) AS result
FROM input
ORDER BY id

2.5 becomes 2, -2.5 becomes -3 and -0.4 becomes -1.

ValueResult
2.52
−2.5−3
0.130
−0.4−1
3.753
null
00
1616

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)

SELECT floor(Qty / 4) * 4 AS result
FROM input
ORDER BY id

7 is in the bin starting at 4, -7 in the bin starting at -8, -1 in the bin starting at -4.

QtyResult
74
−7−8
108
98
20
44
−1−4
00

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

SELECT trunc(Value) AS result
FROM input
ORDER BY id

SQL that matches

SELECT floor(Value) AS result
FROM input
ORDER BY id
ValueTableauTempting SQLSQL that matches
2.5222
−2.5−3−2−3
0.13000
−0.4−10−1
3.75333
nullnullnull
0000
16161616

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 FLOOR(Value) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT FLOOR(Value) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own FLOOR formula return?

Edit the formula and run it on the 8 sample rows. Fields: [id], [Region], [Value], [Qty], [Ratio], [Other].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about FLOOR?

Is FLOOR the same as INT?

Only for positive numbers. INT(-2.5) is -2 (toward zero) while FLOOR(-2.5) is -3.

How do I bin values into steps of 4?

FLOOR([Qty] / 4) * 4 gives the start of each bin: 7 falls in 4, -7 in -8. In SQL, floor(Qty / 4) * 4.

What does FLOOR return for a null?

Null. Row 6 has no value.

Where is this documented?