Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
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.
  • Confusionary Profile Picture
    4 on 11 Jan 2023 at 22:46:34
    mod limitations

    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

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

     

  • David- Profile Picture
    1,254 on 29 Jul 2022 at 19:57:21
    Re: Mod Function with Negative Numbers

    This may help: Power Automate Functions: Mod (Modular) - FlowJoe.io

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

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
Michael E. Gernaey Profile Picture

Michael E. Gernaey 8 Super User 2025 Season 1

#2
ankit_singhal Profile Picture

ankit_singhal 7 Super User 2025 Season 1

#3
David_MA Profile Picture

David_MA 4 Super User 2025 Season 1

Overall leaderboard