cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ahhollan
Post Patron
Post Patron

Invalid Operation: division by zero

I have an app that was working well. However, I now get an Invalid Operation: Division by zero error. I can't seem to find where the error is with the app checker. Does anyone have a suggestion on how to easily find this error?

3 REPLIES 3
Pstork1
Dual Super User
Dual Super User

I had a similar issue with a responsive app I built.  In my case it turned out to be a timing problem.  I was using a value on one of the pages that was calculated at startup based on the app size.  The problem was some other calculations were using it prior to the app fully starting so the value was still zero. I fixed it by adding an if statement around the calculation that checked to see if the size I was using was zero or not before doing the calculation.  That fixed the issue.  

 

I found the equation causing the issue by using the monitor in the designer.  It shows you what happens in the app as it loads and runs.  That's where I found the error flagged.  You can read about the monitor here:

Monitor overview - Power Apps | Microsoft Docs



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365EduCon in Chicago on Sept. 26-30 where I'll be presenting on the Power Platform!
Ethan_R
Super User
Super User

Hi @ahhollan ,

 

I guess you only see this error when you play the App.

Let's consider few scenarios, 

1.  You have created some dynamic stuff on your screen which doesn't load at that instant but the formula executes in order to show you the control or run OnStart while you play the App.

   Consider this example,

If you have a gallery of Tab buttons (say 5 items) and you create a dynamic 'Template Size' formula as such 

Parent.Width/CountRows(Gallery.AllItems)

In this case, when your App runs, Gallery.AllItems may contain 0 records. Thus pushing the error that you got.

To avoid this, if you know that there are 5 items in gallery then insert that in your formula.

Parent.Width/5

 

2. Now let's say you have some collection that executes later or has 0 records and you need to show or create some dynamic content or size of control accordingly. Which will throw the error since collection has 0 records.

   Consider this example,

If you want to show dynamic width of a control based on items in collection.

Add a condition to first null check the items, if its greater than 0 then perform dynamic task.

If(CountRows(colTodaysTask) > 0, <----Your Code---->, Notify("Ërror")(optional) )

 

So basically whenever we have dynamic operations in the App, consider having null checks or initial load up of the screen which depends on some values which populates before the layout than its items or any other possible stuff.

Re-check your formulas.

 

Hope this helps.

So I ran the monitor and the app found one delegation error and another formula error. I fixed the formula error, and the app runs clean in design mode. However, when I open the app normally (not in edit mode) I still get the error. The monitor isn't picking up anything. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (4,659)