OpenBI Docs Buy

MOD

The remainder of a division, with the divisor's sign.

Group: Math. Compatible with DAX.

Syntax

MOD ( <number>, <divisor> )
ParameterTypeDescription
numberNumberThe number to divide.
divisorNumberThe number to divide by; it may not be zero.

Returns

Number. The remainder of the division. It has the sign of the divisor.

Remarks

  • The remainder follows the divisor's sign: MOD ( -7, 3 ) is 2 and MOD ( 7, -3 ) is -2. Some programming languages would say -1 and 1 here.
  • Put another way, the result is number - divisor * INT ( number / divisor ).
  • A divisor of zero, or a blank one, is an error. A blank number gives BLANK.
  • Decimals work too: MOD ( 7.5, 2 ) is 1.5. As with any floating-point number, a result such as MOD ( 2.3, 1 ) may not be exactly 0.3; round it before comparing it with a value.
  • Common uses: every second row (MOD ( [Index], 2 ) = 0), or the position in a cycle of weeks or shifts.

Examples

The sign comes from the divisor

EVALUATE
ROW (
    "7 by 3", MOD ( 7, 3 ),
    "-7 by 3", MOD ( -7, 3 ),
    "7 by -3", MOD ( 7, -3 ),
    "-7 by -3", MOD ( -7, -3 ),
    "7.5 by 2", MOD ( 7.5, 2 )
)
7 by 3-7 by 37 by -3-7 by -37.5 by 2
12-2-11.5

Crates over after full pallets of 8

EVALUATE
ADDCOLUMNS ( DATATABLE ( "Crates", INTEGER, { { 7 }, { 12 }, { 30 } } ), "Left over", MOD ( [Crates], 8 ) )
ORDER BY [Crates]
CratesLeft over
77
124
306

QUOTIENT, INT, DIVIDE, ISEVEN, ISODD.

Last updated · OpenBI Studio 0.3.74