I have a complex expression I'm working with in Power Automate that has been causing some problems. I've narrowed the issue down to the part of the expression that uses the mod function. It produces the expected results if the dividend is not a negative number. When the dividend is a negative number, the result isn't as expected. For example, if in Power Automate I have this function
you are correct result should be 2
power automate mod function works differently from other programs such as excel, python or anything else I have ever tried;
mod(-4,3) should be 2 but instead it is is treating it as -mod(4,3).
you can work around this by checking if the output is greater than 0 displaying the output if true and if false adding the divider
so if(greater(mod(-4,3),0),mod(-4,3),add(3,mod(-4,3)) = 2
obviously this is #1 frustrating and #2 only works for positive divisors
good luck
@maria3 It is evident that this is the case, the question is why ? Sharing a link for further reading and answer to why https://www.geeksforgeeks.org/modulo-operations-in-programming-with-negative-results/ . I believe yours is a classic case, for which you will not find in any power automate demo(no negative numbers in example). Therefore, I would recommend you to change the logic i.e do the mod operation in excel and pull the result in flow if you can.
Hope it helps!!
Cheers,
Ankesh
--------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
This may help: Power Automate Functions: Mod (Modular) - FlowJoe.io
Michael E. Gernaey
8
Super User 2025 Season 1
ankit_singhal
7
Super User 2025 Season 1
David_MA
4
Super User 2025 Season 1