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 / Divide by Zero on Main...
Power Apps
Unanswered

Divide by Zero on Main Page

(0) ShareShare
ReportReport
Posted on by 716 Moderator

So I know what is happening, I just don't know how to fix it.

I have the same problem others have had with setting design layout values that initially throw the error because a value isn't set soon enough at load.

I have a horizontal container that holds a horizontal gallery.

Gallery items are populated with:

Sort(colTabs,ID,SortOrder.Ascending)

colTabs is defined in the OnStart to create the tab values themselves.

The error happens because of this calculation (which is setting template width in the gallery dynamically):

Parent.Width/CountRows(Self.AllItems)

 

I tried using Coalesce as suggested in another post but that didn't work. Although maybe the problem was in my syntax.

The modified code I tested was:

Parent.Width/Coalesce(CountRows(Self.AllItems),200)

 

It didn't work though. I still get a divide by zero error which doesn't make sense to me. If CountRows isn't returning a number, then the Template width should use 200 as the denominator and I shouldn't get an error.

 

Appreciate any guidance provided.

Categories:
I have the same question (0)
  • renatopc84_ch Profile Picture
    228 on at

    Hi @DCHammer 

    You could perform the Countrows in the "OnStart" property of the APP and set it on a variable.

    Then use the variable in your galleries. Otherwise every filter and dependencies would change the template size and this could be recognized as a cycle.

  • DCHammer Profile Picture
    716 Moderator on at

    Thank you for the suggestion. Now I just have to figure out how to do that. I'll readily admit I'm reusing logic from someone else's app and design that I've just modified. I'm really not a developer and it shows. 🙂

  • renatopc84 Profile Picture
    44 on at

    Hi @DCHammer 

     

    You have to copy the Code from “items” Property of the Gallery.

    On the “App” Page you have the property “On Start” (if you should see it, maybe must be activated in the settings of the App).

    There you can add this code:

     

    Set(varNumberRows,CountRows(CodeYouCopiedFromTheGallery))

     

    then you can replace the Self.Allitems with varNumberRows

  • DCHammer Profile Picture
    716 Moderator on at

    Thank you so much. I might need a day to get around to this but I'll update the post and credit you as soon as I make it work.

  • DCHammer Profile Picture
    716 Moderator on at

    Well, I was successful in transferring the calculation to the OnStart property and then using that variable to set the template size.

    It works and the layout is correct but it still throws the divide by zero error at launch. It seems that the app loads the page and tries the generate the html before the OnStart logic completes. But once the code in OnStart finishes the layout adjusts and everything looks right.

    I'd just really like to make that error message at the top disappear. If it automatically removed itself as soon as the denominator wasn't zero, I'd just ignore it. But it stays up there.

     

    Maybe I need to try and use Coalesce on this variable now.

  • Verified answer
    renatopc84_ch Profile Picture
    228 on at

    Hi @DCHammer 

    I had the same issue with another App that shows Graphs.

    I solved it adding the 

    iferror(Formula,"")

     

    So the formula will be executed and calculated, but in case of error nothing will be shown

  • DCHammer Profile Picture
    716 Moderator on at

    Well, it now does EXACTLY what I want it to do. Thank you so much.

     

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard