Tableau function Number

Tableau ROUND to SQL

ROUND(number, [decimals]) rounds to the given number of decimal places, or to a whole number when decimals is left out. A half rounds away from zero: 2.5 becomes 3 and -2.5 becomes -3. DuckDB's round(), Snowflake's and BigQuery's do the same. The hand-rolled floor(x + 0.5) rounds -2.5 up to -2.

Updated · Checked on the xmetric engine

What is the syntax?

ROUND(number, [decimals])
number
the number to round.
decimals
optional: how many decimal places to keep. 0 or omitted rounds to an integer; a negative value rounds to tens, hundreds and so on.

Returns a number rounded to decimals places (a whole number if decimals is omitted). 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 to a whole number?

Tableau

ROUND([Value])

SQL (DuckDB)

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

2.5 becomes 3, -2.5 becomes -3 and 3.75 becomes 4.

ValueResult
2.53
−2.5−3
0.130
−0.40
3.754
null
00
1616

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

What is each value rounded to one decimal?

Tableau

ROUND([Value], 1)

SQL (DuckDB)

SELECT round(Value, 1) AS result
FROM input
ORDER BY id

3.75 becomes 3.8 and 0.125 becomes 0.1.

ValueResult
2.52.5
−2.5−2.5
0.130.1
−0.4−0.4
3.753.8
null
00
1616

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

Where does a straight translation go wrong?

Common mistake

Why does floor(x + 0.5) round -2.5 the wrong way?

Adding a half and flooring sends every half upward: -2.5 becomes -2. Tableau rounds halves away from zero, to -3.

Tableau

ROUND([Value])

Tempting SQL

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

SQL that matches

SELECT round(Value) AS result
FROM input
ORDER BY id
ValueTableauTempting SQLSQL that matches
2.5333
−2.5−3−2−3
0.13000
−0.4000
3.75444
nullnullnull
0000
16161616

The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.

What does each precision return?

The same values with decimals omitted and with two decimals. Columns 1 to 8 are the sample rows, by id.

CaseTableau, then SQL (DuckDB)12345678
default precisionROUND([Value])round(Value)3−3004null016
two decimalsROUND([Value], 2)round(Value, 2)2.5−2.50.13−0.43.75null016

On every row, each Tableau formula and its SQL return the same value.

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

Snowflake documentation

BigQuery

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

BigQuery documentation

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

Which way does ROUND send halves?

Away from zero: 2.5 becomes 3 and -2.5 becomes -3. It isn't banker's rounding.

Why does 9.405 round to 9.40?

Floating point stores 9.405 as slightly less than 9.405, so ROUND(9.405, 2) gives 9.4. Tableau's help notes the same; format the number instead if you only need it displayed.

Can decimals be negative?

ROUND([Value], -1) rounds to tens: 16 becomes 20. DuckDB accepts this too.

Where is this documented?