Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Divide by Zero on Main Page

(0) ShareShare
ReportReport
Posted on by 714 Super User 2025 Season 1

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:
  • DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Divide by Zero on Main Page

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

     

  • Verified answer
    renatopc84_ch Profile Picture
    228 on at
    Re: Divide by Zero on Main Page

    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
    714 Super User 2025 Season 1 on at
    Re: Divide by Zero on Main Page

    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.

  • DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Divide by Zero on Main Page

    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.

  • renatopc84 Profile Picture
    44 on at
    Re: Divide by Zero on Main Page

    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
    714 Super User 2025 Season 1 on at
    Re: Divide by Zero on Main Page

    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_ch Profile Picture
    228 on at
    Re: Divide by Zero on Main Page

    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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

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,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard