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?
Thanks, @WarrenBelz!
Looks like that solved it. Using With() is a much cleaner solution than my original approach.
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, @Gochix.
I tried using IfError() and your If-condition above, but both approaches still result in the "Division by zero" error, unfortunately. 🤔
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%") & ")")
WarrenBelz
146,587
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,928
Most Valuable Professional