May 30, 2025

Power Automate’s “mod” function helps you find the remainder after dividing one number by another. While it might not be the first function that comes to mind when building your Flows, it can be handy for various scenarios. Whether you’re trying to determine if a number is even or odd, need to create a repeating pattern, or want to distribute tasks evenly, the mod function can be your best friend.

Let’s explore how to use it effectively in your Flows.

Where to find it?

You can find the function in every action where a formula is supported. For example, let’s look at a “Compose” action:

As you can see, we can auto-complete by using the “tab” key (old UI) or “enter” key (new UI). Let’s look at how to use it.

Usage

The “mod” function follows a simple pattern:

  1. The dividend (the number being divided)
  2. The divisor (the number to divide by)

Here’s the basic syntax:

mod(dividend, divisor)

This function divides the first number (dividend) by the second number (divisor) and returns the remainder. If you’re familiar with programming, this is equivalent to the modulo operator (% in many programming languages).

For example:

mod(10, 3)

Will return:

1

This is because when you divide 10 by 3, you get 3 with a remainder of 1.

Another example:

mod(15, 5)

Will return:

0

This makes sense because 15 divides perfectly by 5 with no remainder.

Finally it works as well with floating point value. For example:

mod(10.4, 3)

Will work and it will return:

1.4

It’s possible, but I don’t see a potential usage. If you do, please email me and let me know.

Real-world examples

One of the most common uses of the “mod” function is checking whether a number is even or odd. Let’s use a variable called NUMBER_TO_CHECK with a value of 7:

mod(variables('NUMBER_TO_CHECK'), 2)

If the result is 0, the number is even. If the result is 1, the number is odd. In our case, the result would be 1, which means 7 is an odd number.

Another practical use is creating cycles or patterns. For example, if you want to assign tasks to team members in a rotation, you could use the “mod” function to cycle through team members based on a task number:

mod(variables('TASK_TO_CHECK'), length(variables('PEOPLE_IN_THE_TEAM')))

This expression would give you an index that you can use to pick a team member from your array, ensuring that tasks are distributed evenly among your team.

Here’s how it works. To simulate the data, here’s the array created with the “createArray” function, where we simulate three people in the company. We’re always getting the array’s length using the “length” function if you have any other array. Here’s the sample array:

createArray('Alice','Manuel','Bob')

And here’s the function in action, using the “Initialize variable Action”.

So, if the task is a multiple of 3, then ‘Bob’ will take care of it, for example.

Common Mistakes

Here are some common mistakes people make when using the “mod” function:

Division by zero

If you try to use zero as the divisor, you’ll get an error:

mod(10, 0)

The error is usually something like this:

InvalidTemplate
Unable to process template language expressions in action 'Compose_2' inputs at line '0' and column '0': 'Attempt to divide an integral or decimal value by zero in function 'mod'.'.

This will result in an error because division by zero is mathematically undefined.

Always ensure your divisor is not zero before using the “mod” function.

Using strings instead of numbers

The “mod” function expects both parameters to be numbers. If you provide strings, Power Automate will break, so for example:

mod('10', '3')

Will return the following error:

Unable to process template language expressions in action 'Compose_2' inputs at line '0' and column '0': 'The template language function 'mod' expects its first parameter to be an integer or a decimal number. The provided value is of type 'String'. Please see https://aka.ms/logicexpressions#mul for usage details.'.

Please ensure that you have the correct datatypes. If you’re unsure, you can always use the “int” function to check beforehand that the values are valid values.

Limitations

There are a few things to be aware of when using the “mod” function:

Expression size limits

As with all Power Automate expressions, there’s a limit of 8,192 characters. If you’re building complex calculations that include the “mod” function, try to break them up into smaller, manageable pieces using variables.

Recommendations

Here are some things to keep in mind when using the “mod” function:

Use “debug” compose actions

Since the “mod” function does a mathematical operation, sometimes it’s tricky to understand the result, especially with more complex expressions. I recommend using Compose actions to see the intermediate values. If the result doesn’t make sense, you can understand why based on the input parameters.

Consider readability for complex calculations

If you’re using the “mod” function as part of a larger calculation, consider breaking it into multiple steps using variables or compose actions. This will make your Flow easier to understand and maintain.

Always add a comment

Adding a comment will help avoid mistakes. Indicate why you are using the “mod” function and what the expected result means in the context of your Flow. What seems obvious now might not be in a few months. It’s essential to enable faster debugging when something goes wrong.

Check for zero divisors

Before using the “mod” function, ensure that your divisor will never be zero. You can add a condition to check this and handle the case appropriately:

if(equals(variables('DIVISOR'), 0), 0, mod(variables('DIVIDENT'), variables('DIVISOR')))

In this case we’re using the “default” value as ‘0’, but you can put any value you you think it’s appropriate.

This simple check can prevent your Flow from failing with a division by zero error.

Sources

Microsoft’s mod Function Reference

Back to the Power Automate Function Reference.

You can follow me on Mastodon (new account), Twitter (I’m getting out, but there are still a few people who are worth following) or LinkedIn. Or email works fine as well 🙂

Photo by Annie Sowards on Unsplash

 

Manuel

I have 20 years of experience in automation, project management, and development. For the past 6 years, I have been writing for this website, sharing (what I think are) valuable insights and information with readers. I strive to use my expertise to create compelling and informative content that resonates with you and, hopefuly saves you time.

View all posts by Manuel →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon