The Mod function is a mathematical function that calculates the remainder of a number divided by a divisor. It may not be apparent its usage, but it can be quite useful. You can check Power Apps: Formatting user-friendly date ranges, where I provide a complex example by using it in the calculation of days and hours based on time differences.

Let’s go over a couple of examples of *Mod *and how you can use this function.

### Calculate if a number is even or odd

Power Apps doesn’t provide a function to check for this so you can use *Mod function *to help you by using the following formula:

`If(Mod(number,2)=1,"Odd","Even")`

.

You can use this, for example, if you want to display cells in a different color by defining the one for the Odd numbers and another for the Even numbers.

### Calculate if a number is a multiple of another

You can check if a number is a multiple of another by using the following formula:

`If(Mod(number,4)<> 0,"Not Multiple","Multiple") `

.

You can use this if you want to sum the values of each “th” occurrence.

### Calculate the number of days from hours

Let’s say that you want to calculate how many hours your employees worked and check the over-time to pay them. The formula is quite simple:

`Mod(<number of hours worked in a single day>,8) `

.

You can get the total number of hours from the timesheet but to calculate the overtime you need to get the remainder of the division by 8 hours (the overtime).

## Limitations

- You can
*only*nest 50*Mod*statements, but rarely you’ll need to nest*Mod*statements.

## Recommendations:

- Power Apps will return empty values if there is an error in the formula, but won’t return any error. For example,
`Mod(200,0)`

won’t return an error even if it’s mathematically incorrect. Test your app to ensure that your*Mod*always has the parameters that you’re expecting.

## Localization

- Please note that formulas may have localization-based differences. For example, you should write
`Mod(10,3)`

with*“,”*separating each of the arguments, but if your localization is Portugal, you should use*“;”*instead

## Sources:

Back to the PowerApps Function Reference

I think that your formula for even odd is off just a bit. For integers the formula given:

If(Mod(number,2)=1,”Odd”,”Even”)

Will not alternate between “even” and “odd” as desired. You need to set the formula equal to “0”, like so:

If(Mod(number,2)=0,”Odd”,”Even”)

Hi Julian,

Setting to 0 we would need to switch the “odd” and “even” in the formula correct? Like this:

If(Mod(TextInput1.Text,2)=0,”Even”,”Odd”)

I was testing for the remainder or one hence being the odd number, but we can do this :).

Do you have some examples where the alternation fails so that I can include them here and make the reference better?

Thanks!