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 Apps / Invalid Operation: Div...
Power Apps
Answered

Invalid Operation: Division by zero

(0) ShareShare
ReportReport
Posted on by 64

Hi,

 

I have noticed this is starting to happen on my app that is relating to the formula below the screenshot, is anyone able to help, please.

 

The formula is written to show a 3 year depreciation model on a purchase cost value.

 

Surfmania77_0-1643366292461.png

 

If(Round((ThisItem.PurchaseCost / DateDiff(ThisItem.PurchaseDate, DateAdd(ThisItem.PurchaseDate, 3, Years), Days))*DateDiff(ThisItem.PurchaseDate,Today(),Days),2)>=ThisItem.PurchaseCost,
"0",
(ThisItem.PurchaseCost - Round((ThisItem.PurchaseCost / DateDiff(ThisItem.PurchaseDate, DateAdd(ThisItem.PurchaseDate, 3, Years), Days))*DateDiff(ThisItem.PurchaseDate,Today(),Days),2)))
 
Thanks, Craig
Categories:
  • timl Profile Picture
    37,420 Super User 2026 Season 2 on at

    Hi @Surfmania77 

    Assuming that the divisor in your formula isn't resolving to 0, maybe the details in this post might be helpful.

    https://powerusers.microsoft.com/t5/Building-Power-Apps/How-to-remove-system-error-messages-in-canvas/m-p/1432487

     

  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @Surfmania77 ,

    This is most likely as  result of the latest Authoring Versions bug (if it could be called that) causing previous internally handled issues to now produce error messages. NOTE - free-typed below (so watch commas/brackets etc), but you will get the idea - the most important part is the test at the start.

    If(
     ThisItem.PurchaseCost > 0 && Value(ThisItem.PurchaseDate) > 0,
     With(
     {
     wCost:
     Round(
     ThisItem.PurchaseCost / 
     DateDiff(
     ThisItem.PurchaseDate, 
     DateAdd(
     ThisItem.PurchaseDate,
     3,
     Years
     ),
     Days
     )
     )*
     DateDiff(
     ThisItem.PurchaseDate,
     Today(),
     Days
     ),
     2
     )
     },
     If(
     wCost >= ThisItem.PurchaseCost,
     0,
     wCost
     )
     ),
     0
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • Surfmania77 Profile Picture
    64 on at

    Thanks @timl,

     

    You are correct and have already looked at those post that just sends my mind into meltdown lol

  • Surfmania77 Profile Picture
    64 on at

    Sorry, this didn't work for me, I'm fairly green with PowerApps, getting better but some guidance on this is hugely appreciated

  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    @Surfmania77 ,

    That is interesting as I did a test at the top to ensure the elements involved were greater than zero and if not, return a zero. I do not have any more ideas if that is still returning the error.

  • Surfmania77 Profile Picture
    64 on at

    Thanks, mate, what is this referencing?

     

    wCost
  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @Surfmania77 ,

    You can call it whatever you want (see With() function) - that is the naming structure I use. I am just separating the functions with another version of what you are doing.

  • Sri Profile Picture
    559 on at

    Hi @WarrenBelz , 

    In my case I have the same error 

    "Invalid Operation: Division by Zero"

    I have used this formula on the OnSelect and onchange of the datacardvalue which calculates the value and the output is given  & displayed in a textlabel.

    Set(
    schvar,
    ((DataCardValue105.SelectedDate - DataCardValue104.SelectedDate) / (DataCardValue104.SelectedDate - DataCardValue100.SelectedDate)) * 100);
    Set(schvariance, Round(schvar,2));

  • timl Profile Picture
    37,420 Super User 2026 Season 2 on at

    @Uthhra 

    You might consider calling the IfError function to catch the divide by zero error. There's an example in the docs on how to do this.

    https://docs.microsoft.com/en-gb/power-platform/power-fx/reference/function-iferror

     

  • Verified answer
    Sri Profile Picture
    559 on at

    hi @timl,

    I tried using IfError function but still i am getting the same error and its not allowing me to save the form.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard