web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Mod Function with Nega...
Power Automate
Answered

Mod Function with Negative Numbers

(0) ShareShare
ReportReport
Posted on 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.
Categories:
I have the same question (0)
  • David- Profile Picture
    1,254 on at

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

  • Verified answer
    AS-06081019-0 Profile Picture
    1,736 Super User 2024 Season 1 on at

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

     

  • Confusionary Profile Picture
    4 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 594

#2
Valantis Profile Picture

Valantis 328

#3
David_MA Profile Picture

David_MA 281 Super User 2026 Season 1

Last 30 days Overall leaderboard