Tableau function Number

Tableau CEILING to SQL

CEILING(number) rounds up to the nearest integer of equal or greater value: 2.1 becomes 3, -2.5 becomes -2, and a whole number stays put. DuckDB writes it ceil() (or ceiling()). The hand-rolled trunc(x) + 1 is wrong twice: it lifts whole numbers (16 becomes 17) and pushes negatives up too far.

Updated · Checked on the xmetric engine

What is the syntax?

CEILING(number)
number
a number or a numeric expression.

Returns an integer: the smallest whole number not below 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 up?

Tableau

CEILING([Value])

SQL (DuckDB)

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

2.5 becomes 3, -2.5 becomes -2, 0.125 becomes 1, and 16 stays 16.

ValueResult
2.53
−2.5−2
0.131
−0.40
3.754
null
00
1616

The Tableau formula and the SQL return the same 8 rows.

How many boxes of 4 does each quantity need?

Tableau

CEILING([Qty] / 4)

SQL (DuckDB)

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

7 items need 2 boxes, 10 need 3; -7 rounds up to -1.

QtyResult
72
−7−1
103
93
21
41
−10
00

The Tableau formula and the SQL return the same 8 rows.

Where does a straight translation go wrong?

Common mistake

Why does trunc(x) + 1 overshoot?

Adding 1 after truncating works only for positive fractions. It turns 16 into 17 and 0 into 1, and sends -2.5 to -1 instead of -2.

Tableau

CEILING([Value])

Tempting SQL

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

SQL that matches

SELECT ceil(Value) AS result
FROM input
ORDER BY id
ValueTableauTempting SQLSQL that matches
2.5333
−2.5−2−1−2
0.13111
−0.4010
3.75444
nullnullnull
0010
16161716

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

Snowflake documentation

BigQuery

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

BigQuery documentation

What does your own CEILING 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 CEILING?

Which way does CEILING round negatives?

Up, toward positive infinity: -2.5 becomes -2 and -0.4 becomes 0. For "away from zero", use SIGN(x) * CEILING(ABS(x)).

How do I round up to a number of boxes?

CEILING([Qty] / 4) is the boxes needed for packs of 4: 7 items need 2. In SQL ceil(Qty / 4).

What does CEILING return for a null?

Null. Row 6 has no value.

Where is this documented?