Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building 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:
  • Siddz Profile Picture
    on at
    Re: "Invalid operation: Division by zero" when counting gallery items

    Thanks, @WarrenBelz!

     

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

  • Verified answer
    WarrenBelz Profile Picture
    146,587 Most Valuable Professional on at
    Re: "Invalid operation: Division by zero" when counting gallery items

    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
    Re: "Invalid operation: Division by zero" when counting gallery items

    Thanks, @Gochix.

     

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

     

  • Gochix Profile Picture
    1,933 Super User 2025 Season 1 on at
    Re: "Invalid operation: Division by zero" when counting gallery items

    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%") & ")")

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,587 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,928 Most Valuable Professional

Leaderboard