cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HimanshuSSharma
Resolver I
Resolver I

What is the use of IfError?

Hi Community,

Am I doing something wrong here:

HimanshuSSharma_0-1614347360014.png

 

It is essentially IfError(A/B,0) returning an error!!

BTW this is a case where B is 0 (#Div in Excel)

Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@HimanshuSSharma 

If you're trying to set a color from this, then this formula should be giving you what you want:

If(IfError(Value(Label_FYtblFcst_3.Text) / Value(Label_FytblFcst7.Text), 0) = 0, Blue, Green)

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@HimanshuSSharma 

Beside the message in the formula editor (which is very often misleading), what issue are you seeing with the formula?  If should be returning the values of the two Text's divided, or a 0 if there is an error.

 

If any part of the formula evaluates to blank, the formula editor will usually show that it can't evaluate the expression.  But, your end result in the app should be functional.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
HimanshuSSharma
Resolver I
Resolver I

@RandyHayes So I am expecting a number value as output, and since the denominator is 0 I am expecting the result to be 0 as well (as the first fallback). My next logic says that if the value is 0, colour it blue which was not happening.

 

You are correct in saying that if any formula evaluates to blank- because if I use If(IsBlankOrError(A/B),0,A/B) it gives me the correct result of colour blue, but it is suboptimal as I have to calculate twice.

Maybe we need and IfBlankOrError to make IfError more useful??

RandyHayes
Super User
Super User

@HimanshuSSharma 

If you're trying to set a color from this, then this formula should be giving you what you want:

If(IfError(Value(Label_FYtblFcst_3.Text) / Value(Label_FytblFcst7.Text), 0) = 0, Blue, Green)

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

HimanshuSSharma
Resolver I
Resolver I

@RandyHayes This helps, but I was trying to avoid doing calculation again.
My logic was I had a label.text = IfError(Value(Label_FYtblFcst_3.Text) / Value(Label_FytblFcst7.Text), 0)

and then

if(label.text = 0, blue, green)

This is returning green as when I check label.text in formula bar, it says "Powerapps encountered an error...."

eventually ended up using If(IsBlankOrError(label.text),blue,label.text = 0, blue, green)  which seems to defeat the purpose of IfError, hence the question.

 

Thanks!

RandyHayes
Super User
Super User

@HimanshuSSharma 

I'm not sure what you mean by doing it twice?  

You are only doing the formula once and providing a default if there is an error, then setting a color based on that.


If you need to know what the outcome was (in terms of was it blue or green) you can always reference your control by its color:

   If(yourControl.Fill = Green, "Yay!", "Boo!")

Or whatever property you are setting the color on.

No need for an extra label for this.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,240)