# 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 Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

This site uses Akismet to reduce spam. Learn how your comment data is processed.