OpenBI Docs Buy

MROUND

Takes a number to whichever multiple of a step lies closest, such as the nearest quarter hour.

Group: Math. Compatible with DAX.

Syntax

MROUND ( <number>, <multiple> )
ParameterTypeDescription
numberNumberThe number to bring to a multiple.
multipleNumberThe multiple to round to, such as 5, 0.25 or 0.05. It must have the number's sign.

Returns

Number. The multiple of the second number nearest to the first; a half goes away from zero.

Remarks

  • Number and multiple must have the same sign: MROUND ( -10, 3 ) is an error, MROUND ( -10, -3 ) is -9.
  • A half goes away from zero: MROUND ( 7.5, 5 ) is 10 and MROUND ( -2.5, -1 ) is -3.
  • Floating point can decide a half. 6.05 divided by 0.1 comes out a hair below 60.5, so MROUND ( 6.05, 0.1 ) is 6, while MROUND ( 6.15, 0.1 ) is 6.2. To round to decimals, ROUND rounds such numbers as they are written: ROUND ( 6.05, 1 ) is 6.1.
  • A multiple of 0 gives 0. A blank number gives BLANK.
  • To always go up or down to the multiple, use CEILING or FLOOR.

Examples

Hours to the nearest quarter

Next to CEILING (always up) and FLOOR (always down).

EVALUATE
ADDCOLUMNS (
    DATATABLE ( "Hours", DOUBLE, { { 7.2 }, { 7.25 }, { 7.6 } } ),
    "Nearest", MROUND ( [Hours], 0.25 ),
    "Up", CEILING ( [Hours], 0.25 ),
    "Down", FLOOR ( [Hours], 0.25 )
)
ORDER BY [Hours]
HoursNearestUpDown
7.27.257.257
7.257.257.257.25
7.67.57.757.5

A half decided by floating point

EVALUATE
ROW (
    "MROUND ( 6.05, 0.1 )", MROUND ( 6.05, 0.1 ),
    "MROUND ( 6.15, 0.1 )", MROUND ( 6.15, 0.1 ),
    "ROUND ( 6.05, 1 )", ROUND ( 6.05, 1 )
)
MROUND ( 6.05, 0.1 )MROUND ( 6.15, 0.1 )ROUND ( 6.05, 1 )
66.26.1

Negative numbers need a negative multiple

EVALUATE
ROW ( "-10 to -3", MROUND ( -10, -3 ), "-2.5 to -1", MROUND ( -2.5, -1 ) )
-10 to -3-2.5 to -1
-9-3

ROUND, CEILING, FLOOR, ISO.CEILING.

Last updated · OpenBI Studio 0.3.74