MOD
MOD('Number', 'Divisor' [, "Validation"])
The MOD function returns the remainder value after performing a division operation between two nodes. The input values are 'Number', 'Divisor', and an optional validation option. If no validation is required, the same result can be achieved using the % symbol, for example 'Number' % 'Divisor'. The operation is performed along the linked levels between the nodes.
Use this function when you need the remainder after dividing one value by another, for example for bucket logic or periodic patterns.
Parameters
- NumberNode referenceRequired
- Input node.
- DivisorNode referenceRequired
- Input node.
- ValidationKeywordOptional
- Causes the node executing the function to error with a message explaining why if conditions are not met. Note that using validation can affect performance. Default:
"NoValidation"."NoValidation": Behaves the same as using the%symbol. This is the default."FailOnMissingFirst": The calculation fails if any row in'Number'is not matched with any row in'Divisor'."FailOnMissingSecond": The calculation fails if any row in'Divisor'is not matched with any row in'Number'."FailOnMissing": Combines"FailOnMissingFirst"and"FailOnMissingSecond"validation options.
Watch out
- The result is the remainder of the division and keeps the decimal places of the inputs:
10.5 % 3is1.5. You only get whole numbers back if both inputs are whole numbers. - A missing Number counts as 0, so the row still appears in the result with the value 0. A missing or zero Divisor removes the row.
Examples
Modulo with missing matches and division by zero
This example shows how MOD behaves when rows are matched normally, when a divisor is zero, and when rows are missing on one side.
Input node: 'Node A'
| Year | Volume |
|---|---|
| 2025 | 10 |
| 2026 | 10 |
| 2027 | 5 |
| 2028 | 0 |
| 2029 | 7 |
Input node: 'Node B'
| Year | Volume |
|---|---|
| 2025 | 6 |
| 2026 | 10 |
| 2027 | 0 |
| 2028 | 5 |
| 2030 | 3 |
Formula: MOD('Node A', 'Node B')
Equivalent to: MOD('Node A', 'Node B', "NoValidation")
Equivalent to: 'Node A' % 'Node B'
| Year | MOD Result |
|---|---|
| 2025 | 4 |
| 2026 | 0 |
| 2028 | 0 |
| 2030 | 0 |
Note: The year 2027 has no result because it is not possible to perform 5 % 0, that is, divide by 0. The year 2029 has no result either: 'Node B' has no value there, and a missing divisor removes the row. 2030 is the other way round, missing in 'Node A'. A missing number is treated as 0, so the row survives with the result 0.
Related
- DIVISION (/)
- When you need the quotient of a division instead of the remainder after division.
- ROUND
- When you want to round numeric values instead of calculating a remainder.