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

    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.

    Column NameData Type
    Employee IDIt is a default single line of text
    NameA single line of text
    EmailA single line of text
    GenderChoice
    Joining DateDate and time
    DepartmentLookup
    powerapps mod

    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:

    powerapps mod function

    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
    mod power apps

    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
    mod powerapps

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

    mod function in powerapps

    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
    mod function powerapps

    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 divide function

    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
    PowerApps Mod Calculate Number of Days from Hours

    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
    Power Apps Mod Calculate If Number is Multiple of Another

    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:

    SuggestionsDetermination
    While working with the Power Apps Mod function, follow this recommendation: If the formula contains an error, Power Apps will not return empty or null values instead of any errorAs you may know, some of the Power Apps formulas have locality-based differences. Among them, this PowerApps Mod function also has its functionality
    Suppose the formula is Mod(300,0); then, in this case, it will give an error [Invalid operation: division by zero.]
    powerapps mod function limitation
    For example, if you write the code as Mod(20,5), then it should separate each of the arguments with a comma (,). But if your localization is something else, like France, then you need to use a semicolon (;) instead.
    mod function example

    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:

    comment_count comments
    Oldest
    Newest
    Oldest

    Comment as a guest:

    >