cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Siddz
Super User
Super User

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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

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

View solution in original post

4 REPLIES 4
Gochix
Solution Sage
Solution Sage

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

Thanks, @Gochix.

 

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

 

WarrenBelz
Super User
Super User

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

Thanks, @WarrenBelz!

 

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

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,195)