Skip to main content

Notifications

Community site session details
Power Automate - General Discussion
Answered

Mod Function with Negative Numbers

Like (0) ShareShare
ReportReport
Posted on 29 Jul 2022 19:15:37 by 15

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

mod(sub(7,11),3) the result is -1. However, I would expect that the result should be 2. If I use an equivalent function in Excel =MOD((7-11),3) I get 2 as I would expect. Why should the result be different? In this example shouldn't the result from the Power Automate function be 2? Again, it seems this issue only occurs when the dividend is a negative number. Any help or thoughts on this would be much appreciated.
  • Verified answer
    AS-06081019-0 Profile Picture
    1,736 Super User 2024 Season 1 on 29 Jul 2022 at 20:55:43
    Re: Mod Function with Negative Numbers

    @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.

     

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - General Discussion

#1
David_MA Profile Picture

David_MA 10 Super User 2025 Season 1

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 8 Super User 2025 Season 1

#3
ankit_singhal Profile Picture

ankit_singhal 7 Super User 2025 Season 1

Overall leaderboard