# Power Apps: Mod Function

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

1. You can onlyÂ nest 50 Mod statements, but rarely youâ€™ll need to nest ModÂ statements.

## Recommendations:

1. 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

1. 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:

Mod function in Power Apps

Back to the PowerApps Function Reference

Featured Image by Alex on Unsplash

#### Manuel Gomes

I'm a previous Project Manager, and Developer now focused on delivering quality articles and projects here on the site. I've worked in the past for companies like Bayer, Sybase (now SAP), and Pestana Hotel Group and using that knowledge to help you automate your daily tasks

View all posts by Manuel Gomes →

## 2 thoughts on “Power Apps: Mod Function”

1. 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”)

1. 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!