# 4 Various Power Apps Mod Function Examples

As a Power Apps developer, you must know about all the Functions in Power Apps. One of the most useful is the Mod function.

In this Power Apps tutorial, I will explain the Power Apps Mod function and its syntax. Also, we will discuss how to work with Power Apps Mod calculate if number is even or odd; Power Apps Mod Calculate Number of Days from Hours with various use cases.

## Power Apps Mod Function

In Power Apps, the Mod function helps return the remainder after a number is divided by a divisor. It is one of the most important and useful functions in Power Apps.

Syntax of the Power Apps Mod() Function:

``Mod( Number, Divisor )``

Where,

• Number = This is required. Here, you need to specify a number to divide
• Divisor = This is required. Here, you need to specify a number to divide by

## Power Apps Mod Function Example

Now, I will show you how to work with the Power Apps Mod function using a simple scenario:

Scenario:

I have a SharePoint list named “Employee Onboarding” and this list contains the below fields.

I want to display these SharePoint list items on the Power Apps Gallery control with an alternative color. That color will depend on whether the number is even or odd.

Output:

To work around this, follow the below steps. Such as:

1. On the Power Apps Screen -> Insert a Gallery control and set its Items property to the code below.

``Items = 'Employee Onboarding'``

Where,

• ‘Employee Onboarding’ = SharePoint Online list

2. Now, set the TemplateFill property of the gallery control using the code below.

``````TemplateFill = If(
Mod(
ThisItem.ID,
2
) = 0,
Color.LightBlue,
Color.LightYellow
)``````

Where,

• ThisItem.ID = SharePoint list ID column
• 2 = Even number

3. Finally, Save, Publish, and Preview the app. The gallery control displays with an alternative color based on the even number, as shown below.

## Power Apps Mod Calculate If Number is Even or Odd

In this example, we will discuss how to calculate whether a number is even or odd using the Power Apps Mod function. To do so, follow the code below.

``````Text = If(
Mod(
8,
2
) = 1,
"Odd Number",
"Even Number"
)``````

Where,

• 8 = Even number

In the same way, if you provide an odd number [5] in the Power Apps Mod function, it will return the text value as “Odd Number,” as shown below.

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

Where,

• 5 = Odd Number

## Power Apps Mod Calculate Number of Days from Hours

Suppose you want to check how many hours an employee worked, and you need to check his overtime to pay him/her. To achieve this, you can use the below formula:

``Mod(12,9)     //Mod(<number of hours worked in day>,9)``

Where,

• 12 = Number of hours worked in the day
• 9 = Actual hours in the day

## Power Apps Mod Calculate If Number is Multiple of Another

In this example, I will show you how to check the Power Apps Mod calculate if the number is multiples of another. To do so, follow the code below.

``````Text = If(
Mod(
txt_Number.Value,
5
) <> 0,
"This is Not Multiple",
"This is Multiple"
)``````

Where,

• txt_Number = Power Apps text input name
• 5 = To check the multiples of 5

This is how to check if a number is a multiple of another using the Power Apps Mod function.

## Power Apps Mod Function Limitations

Lastly, we will see the Power Apps Mod function limitations [You can use only 50 Mod statements, and that is to be 50 nest mod statements].Refer to the below table:

From this Power Apps tutorial, we learned the Power Apps Mod function and its syntax and how to use the Power Apps Mod function using different real-time scenarios. Such as:

• Power Apps Mod Calculate If Number is Even or Odd
• Power Apps Mod Calculate Number of Days from Hours
• Power Apps Mod Calculate If Number is Multiple of Another

Also, you may like: