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> )
| Parameter | Type | Description |
|---|---|---|
number | Number | The number to bring to a multiple. |
multiple | Number | The 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 andMROUND ( -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, whileMROUND ( 6.15, 0.1 )is 6.2. To round to decimals,ROUNDrounds 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
CEILINGorFLOOR.
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]
| Hours | Nearest | Up | Down |
|---|---|---|---|
| 7.2 | 7.25 | 7.25 | 7 |
| 7.25 | 7.25 | 7.25 | 7.25 |
| 7.6 | 7.5 | 7.75 | 7.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 ) |
|---|---|---|
| 6 | 6.2 | 6.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 |
Related functions
ROUND, CEILING, FLOOR, ISO.CEILING.