Number.Round(), Number.RoundUp() & Number.RoundDown()

Learn how Number.Round, Number.RoundUp, and Number.RoundDown differ, why Number.Round(2.5) returns 2, why Power Query's RoundUp is not Excel's ROUNDUP for negative numbers, and how negative digits round to the left of the decimal point.

Number.Round(), Number.RoundUp() & Number.RoundDown()

These three round a number, but not the same way. Number.Round() rounds to the nearest value. Number.RoundUp() and Number.RoundDown() always move in a fixed direction: up toward positive infinity, or down toward negative infinity, however close the value already is.

Two of their behaviours differ from Excel and DAX, and both catch people out: ties round to even by default, and RoundUp on a negative number moves toward zero.

Number.Round(number as nullable number, optional digits as nullable number, optional roundingMode as nullable number) as nullable number
Number.RoundUp(number as nullable number, optional digits as nullable number) as nullable number
Number.RoundDown(number as nullable number, optional digits as nullable number) as nullable number
Number.RoundAwayFromZero(number as nullable number, optional digits as nullable number) as nullable number

All of them return null for a null input rather than erroring.


Basic Example

Number.Round(3.14159, 2)
3.14159 -> 3.14

digits defaults to 0 if omitted, rounding to the nearest whole number.


Number.Round Breaks Ties to Even

When a value sits exactly halfway, Number.Round() doesn't round it up. By default it picks the nearest even number (RoundingMode.ToEven, also called banker's rounding).

Number.Round(2.5)
Number.Round(3.5)
Number.Round(-2.5)
Number.Round(2.5)  -> 2     <- not 3
Number.Round(3.5)  -> 4
Number.Round(-2.5) -> -2

Excel's ROUND() and DAX's ROUND() both round half away from zero, so the same value can round differently in Power Query and in a measure. To get the Excel behaviour in M, pass a rounding mode:

Number.Round(2.5, 0, RoundingMode.AwayFromZero)   // 3
Rounding modeWhat happens on an exact tie
RoundingMode.ToEven (default)Round to the nearest even number
RoundingMode.AwayFromZeroRound away from zero (Excel and DAX ROUND)
RoundingMode.TowardZeroRound toward zero
RoundingMode.UpRound up
RoundingMode.DownRound down

The mode only matters for ties: Number.Round(2.6) is 3 under every mode.


RoundUp Means Toward Positive Infinity

Number.RoundUp() returns the next highest number, which makes it a ceiling function. Number.RoundDown() is a floor.

Number.RoundUp(2.1)
Number.RoundUp(-2.1)
Number.RoundDown(2.9)
Number.RoundDown(-2.9)
Number.RoundUp(2.1)    -> 3
Number.RoundUp(-2.1)   -> -2    <- toward zero, not -3
Number.RoundDown(2.9)  -> 2
Number.RoundDown(-2.9) -> -3    <- away from zero, not -2

For positive numbers this matches Excel's ROUNDUP() and ROUNDDOWN(). For negative numbers it's the opposite: Excel's and DAX's ROUNDUP(-2.1, 0) return -3, because they round away from zero. The M function that does that is Number.RoundAwayFromZero():

Number.RoundAwayFromZero(-2.1) -> -3
Number.RoundAwayFromZero(2.1)  -> 3

Try it live

FieldValue
Number
Digits
Number.Round(-2.1, 0)
Number.RoundUp(-2.1, 0)
Number.RoundDown(-2.1, 0)
Number.RoundAwayFromZero(-2.1, 0)

Round

-2

RoundUp

-2

RoundDown

-3

RoundAwayFromZero

-3

— RoundUp moved toward +∞ (-2), which for a negative number means toward zero. Excel's ROUNDUP matches RoundAwayFromZero (-3) instead

Try a negative number such as -2.1, then a tie such as 2.5. RoundUp and RoundDown always move the same direction on the number line, whatever the sign.


Negative Digits Round to the Left of the Decimal Point

The digits argument isn't limited to positive values. A negative digit count rounds to the nearest ten, hundred, thousand, and so on, instead of to a decimal place.

Number.Round(1234, -2)
1234 -> 1200   (rounded to the nearest hundred)
digits =  2  -> nearest 0.01
digits =  0  -> nearest whole number
digits = -2  -> nearest 100
digits = -3  -> nearest 1000

A manual divide, round, and multiply-back pattern works too, but Number.Round(value, -2) does the same thing directly.


Common Mistakes

Expecting 2.5 to Round to 3

Number.Round(2.5) returns 2. If totals rounded in Power Query don't match the same values rounded in Excel or in a DAX measure, the default tie-breaking is the usual reason. Pass RoundingMode.AwayFromZero when the result has to match.

Using RoundUp Where Excel's ROUNDUP Was Meant

Formulas ported from Excel often turn ROUNDUP into Number.RoundUp. That's identical for positive values and wrong for negative ones: Number.RoundUp(-2.1) is -2, while ROUNDUP(-2.1, 0) is -3. Use Number.RoundAwayFromZero to keep Excel's behaviour.

Manually Rounding to Hundreds or Thousands

Number.Round(value / 100, 0) * 100

This works, but Number.Round(value, -2) does the same rounding in one call.

Forgetting digits Defaults to Whole Numbers

Number.Round(3.14159) with no second argument returns 3. Omitting digits doesn't mean "don't round"; it means "round to 0 decimal places".


Best Practices

  • Use Number.Round() for nearest-value rounding, and decide on the tie-breaking mode deliberately when the numbers must match Excel or DAX.
  • Use Number.RoundUp/Number.RoundDown when you want a ceiling or floor, and Number.RoundAwayFromZero when you want Excel's ROUNDUP behaviour.
  • Use a negative digits value to round to tens, hundreds, or thousands directly.

Next Steps