Handling the division by zero error in Power Apps

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… READ MORE [https://lewisdoes.dev/
crop anonymous economist using calculator app on smartphone at work
Photo by Karolina Grabowska on Pexels.com
In: Low Code Lewis Content 🚀

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!

Subscribe

Division 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.

Written by
Lewis Baybutt
Microsoft Business Applications MVP • Power Platform Consultant • Blogger • Community Contributor • #CommunityRocks • #SharingIsCaring
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to LewisDoesDev.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.