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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / "Invalid operation: Di...
Power Apps
Answered

"Invalid operation: Division by zero" when counting gallery items

(0) ShareShare
ReportReport
Posted on by

In my canvas app that's connected to a SharePoint list, I have a gallery with single-select checkboxes. I created a label outside the gallery to count the number of "true" checkbox values in the gallery.

 

An example of the label's output is:

5 of 10 items completed (50%)

The label's Text property is:

CountRows(Filter(Gallery.AllItems, Checkbox.Checked = true)) & " of " & 
CountRows(Gallery.AllItems) & " items completed (" &
Text(CountRows(Filter(Gallery.AllItems, Checkbox.Checked = true)) /
CountRows(Gallery.AllItems) * 100, "[$-en-Us]0%") & ")"

This works well, but each time the app starts, I get this error: "Invalid operation: Division by zero."

 

In the app's settings under "Experimental," I have "Formula-level error management" turned on. (If I turn it off, my gallery doesn't patch to SharePoint correctly for some reason).

 

Any ideas on how to satisfy the "Division by zero" error?

Categories:
I have the same question (0)
  • Gochix Profile Picture
    1,935 Moderator on at

    Hi @Siddz ,

     

    I know this sounds silly but have you tried to implement IfError for this issue?

    Or try to use a checker and see if this helps the issue with error.

    If(CountRows(Filter(Gallery.AllItems, Checkbox.Checked = true)) < 0,"0 of 10 items completed (0%)",
    CountRows(Filter(Gallery.AllItems, Checkbox.Checked = true)) & " of " & 
    CountRows(Gallery.AllItems) & " items completed (" & 
    Text(CountRows(Filter(Gallery.AllItems, Checkbox.Checked = true)) / 
    CountRows(Gallery.AllItems) * 100, "[$-en-Us]0%") & ")")
  • Siddz Profile Picture
    on at

    Thanks, @Gochix.

     

    I tried using IfError() and your If-condition above, but both approaches still result in the "Division by zero" error, unfortunately. 🤔

     

  • Verified answer
    WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @Siddz ,

    Firstly try this to get rid of the error - if you get 0%, then there is something wrong with your filter

    With(
     {
     wCount: 
     CountRows(Gallery.AllItems),
     wChecked:
     CountRows(
     Filter(
     Gallery.AllItems,
     Checkbox.Checked
     )
     )
     },
     wChecked & " of " & wCount & " items completed (" & 
     If(
     wChecked > 0 && wCount > 0,
     Text(
     wChecked / wCount * 100,
     "[$-en-Us]0%"
     ),
     "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

  • Siddz Profile Picture
    on at

    Thanks, @WarrenBelz!

     

    Looks like that solved it. Using With() is a much cleaner solution than my original approach. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard