Scenario background
Do you ever have cases where you’re using a divide in Power Apps. Let’s think of a common idea being calculating percentages. You might be producing a gallery that needs a percentage of progress of something on each record, or perhaps you’re trying to render a chart which shows the progress of a wider project or selected activity.
Do you like this type of content? Issue resolutions seem helpful? Make sure you subscribe to my blog to get daily posts in your inbox on Microsoft 365, low code and more!
SubscribeDivision by zero
Now what happens if you’ve got a case where a user is new to a team for example, and they haven’t got any tasks in a project say yet… This means they won’t have any data or ‘rows’ or figures to do a calculation with resulting in our formula appearing something like (0 / 0) * 100.
The main issue with this is that if we try to divide a number by 0 in Power Apps, we’ll get an error that we’re trying to do an invalid operation.
Handling the error
Now there’s bound to be cases where our users don’t have any records, because say they’ve just joined the team, or there’s another reason that our dynamic value results in being 0. So we need a way to handle that! Let’s now look at how to handle the error of division by 0 in Power Apps.
We’re very simply going to take a formula that looks like this…
(0/0) * 100
and use an IfError() function to change it to look something more like this…
IfError( (0/0) * 100, 0)
Here we’re basically saying that if we don’t have any records and we do a division by 0 which will of course return the error we’re familiar with, now don’t return the error and instead handle it by returning the value following the comma in the IfError() function which in my case I’ve made 0.
Hopefully you found this helpful to resolving the division by zero error in Power Apps! If you didn’t understand something, or have a better solution, let me know in the comments below.