Using the Mod function in an expression in Power Automate, you can quickly determine whether any numeric value is odd or even. In this post’s examples, I’ll be using a SharePoint item (or document) ID field as my numeric value, and I will determine if it is odd or even.
Did you know?
Every item and document in SharePoint is automatically assigned a unique ID number within its list or library. The field is called ID.
What is the Mod Function?
The Mod function takes two arguments: the number you want to divide and the divisor. It returns the remainder of the division. For example,
Mod(5,2) returns 1, because 5 divided by 2 has a remainder of 1.
To check if a number is odd or even, you can use the Mod function with 2 as the divisor and compare the result (using the equals function) with 1. If the result is 1, then the number is odd. If the result is 0, then the number is even.
You can use the if and equals functions together to write this logic as a conditional expression. Here is an example using a SharePoint item ID as the number:
This expression says: if the SharePoint item ID divided by 2 has a remainder of 1, then return ‘Odd’, otherwise return ‘Even.’
You can use any numeric field instead of the SharePoint item ID, as long as it is available in your flow.
You can learn more on the Mod function here.
How to Add the Expression to Your Power Automate Flow
Tip: I have a video of these steps if you’d prefer.
First, to begin adding your expression, click within a step’s field where you want Odd or Even to be returned, such as a variable or condition statement. Then, in the dynamic content panel that pops out, select Expression and you’ll be provided with a formula bar.
In your expression formula bar, use the following formula (modifying the field reference to your own numeric field):
This says if my numeric field divided by 2 has a remainder of 1 (making it an uneven quotient) then it’s odd, otherwise it’s even.
You can then use the result of this expression (Odd or Even) in further conditional expressions or condition blocks like this:
How to Insert a Dynamic Content Field into the Expression
If you are not sure how to find the reference for your numeric field, you can use the dynamic content panel to insert it into your expression. Here are the steps:
- Write your expression up until the point you need to enter the field name
- With your cursor active where you want to enter the field name (right after Mod( in my example), select Dynamic content, then select the numeric field you are using. In my case, it’s the ID field from a SharePoint list item.
- The selected field reference will automatically appear in your formula where your cursor was at the time of insert.
- Finish your expression. It might resemble this if you’re referencing a SharePoint item’s ID from a trigger like When an item is created:
That’s it! You have learned how to use the Mod function in Power Automate to determine if a numeric value is odd or even. I hope this helps you create more powerful and sophisticated flows. Good luck!