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 numberAll of them return null for a null input rather than erroring.
Basic Example
Number.Round(3.14159, 2)3.14159 -> 3.14digits 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) -> -2Excel'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 mode | What happens on an exact tie |
|---|---|
RoundingMode.ToEven (default) | Round to the nearest even number |
RoundingMode.AwayFromZero | Round away from zero (Excel and DAX ROUND) |
RoundingMode.TowardZero | Round toward zero |
RoundingMode.Up | Round up |
RoundingMode.Down | Round 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 -2For 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) -> 3Try it live
| Field | Value |
|---|---|
| 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
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 1000A 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) * 100This 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.RoundDownwhen you want a ceiling or floor, andNumber.RoundAwayFromZerowhen you want Excel'sROUNDUPbehaviour. - Use a negative
digitsvalue to round to tens, hundreds, or thousands directly.
Next Steps
- M Language
- Table.TransformColumnTypes()
- Number.ToText(): formatting a number for display, including the "P" percent gotcha
- M Function Reference
Working with Dates in Power Query (Date & Duration Functions)
Learn the core Date.* and Duration.* functions in Power Query M — adding/subtracting time, extracting components, and the Duration vs. DateTime distinction that trips people up.
Csv.Document()
Learn what Csv.Document actually returns before Table.PromoteHeaders runs — generic Column1/Column2 names and every value as text, not the named, typed columns the Get Data wizard makes it look like.