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 / I am trying to solve t...
Power Apps
Answered

I am trying to solve this notification bug out of my power-app. "Invalid Operation: division by zero"

(0) ShareShare
ReportReport
Posted on by

I am trying to get the percentage of Total Check Ins and Check Outs out of Total Appointments and it's working but when I open my powerapps through sharepoint it gives me this error, "Invalid Operation: division by zero." If anyone can help me fixing it, I would really appreciate it.
This is my code on the OnStart property of Screen:

ClearCollect(
colAppointmentsWithoutRN,
Appointments
);
ClearCollect(
colAppointments,
ForAll(
Sequence(CountRows(colAppointmentsWithoutRN)),
Patch(
Last(
FirstN(
colAppointmentsWithoutRN,
Value
)
),
{RowNumber: Value}
)
)
);
Set(
varRowsPerPage,
7
);
Set(
varCurrentPage,
1
);
Set(
varTotalPages,
RoundUp(
CountRows(colAppointments) / varRowsPerPage,
0
)
);
Set(
isTimerStart,
true
);
Set(
varStartTimer,
true
);

// Gallery Code Ends

Set(
varDistVARep,
Distinct(
colAppointments,
'VA Representative'
)
);
ClearCollect(
colAppointmentsWithDiff,
AddColumns(
colAppointments,
"TimeDifference",
DateDiff(
'Check-in time',
//'Checkout time',
'Appointment-Ends',
TimeUnit.Minutes
)
)
);

Set(varTotalTimeDifference, Sum(colAppointmentsWithDiff, TimeDifference));

Set(
varTotalRep,
CountRows(varDistVARep)
);
Set(
varTotalAppointments,
CountRows(colAppointments)
);
Set(
varTotalCheckIn,
CountRows(
Filter(
colAppointments,
Status.Value = "Checked-in"
)
)
);
Set(
varTotalCheckOut,
CountRows(
Filter(
colAppointments,
Status.Value = "Checked-out"
)
)
);
Set(
varCheckInPercet,
Text(varTotalCheckIn / varTotalAppointments) * 100 & " %"
);
Set(
varCheckOutPercet,
Text(varTotalCheckOut / varTotalAppointments) * 100 & " %"
);

Clear(colPiCharData);
Collect(
colPiCharData,
{
Status: "Check In",
Count: varTotalCheckIn
}
);
Collect(
colPiCharData,
{
Status: "Check Out",
Count: varTotalCheckOut
}
);

And here is the error again:

MOALI_1-1699236003066.png

 

 

Categories:
I have the same question (0)
  • EddieE Profile Picture
    4,641 Moderator on at

    @Anonymous 

    Basically, some of the code is processing faster than your code needs it to. For example, this code

    ClearCollect(
    colAppointments,
    ForAll(
    Sequence(CountRows(colAppointmentsWithoutRN)),
    Patch(
    Last(
    FirstN(
    colAppointmentsWithoutRN,
    Value
    )
    ),
    {RowNumber: Value}
    )
    )
    );

    is still running when the app gets to this code, where it needs the above to be complete

    Set(
    varTotalPages,
    RoundUp(
    CountRows(colAppointments) / varRowsPerPage,
    0
    )
    );

     

    One thing you can try is to add a Timer to your Home screen, set it's duration to say 100 milliseconds (you may need to play around with this number), then move all the code that using division to the OnTimerEnd property.

     

    Once you get it working, just set the Timer Visible property to false and send to the bottom of the tree view (Send to Back)

  • Community Power Platform Member Profile Picture
    on at

    Can you explain it a little bit more and a bit more easier? So i have a auto scroll gallery bc of my code in the timer that i already have to make the gallery scrollable.

    MOALI_0-1699237970620.png

     

  • Community Power Platform Member Profile Picture
    on at

    I already tried to add the division formula as you have mentioned  but it didn't work.

  • EddieE Profile Picture
    4,641 Moderator on at

    @Anonymous 

    So as not to confuse your other timer, add a separate timer to your app. Then, move all Set() code that uses a division calculation to this timers' OnTimerEnd property.

     

    You may need to double check that any code you move doesn't affect code you already have setup in the App OnStart

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    I used the IfError() function and it worked. Thank You.

  • EddieE Profile Picture
    4,641 Moderator on at

    @Anonymous 

    That's great, well done. You can go ahead and mark your last post as the solution as this helps anyone else find it in the future.

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard