We help IT Professionals succeed at work.
Get Started

"Attempted to divide by zero" When trying to compute percentage with formula

Last Modified: 2015-05-07
The formula below would work but I receive a runtime error "cannot divide by zero" because it looks like even if the condition is evaluated as true it still evaluates both parts before it decides which value to return. I've read articles that say there is a workaround but I don't know how to adapt it exactly. It says you can use nested iif statements. Can someone tell me how I can adapt my formula to this
Example that should circumvent the divide by 0 issue
=IIf(Fields!SomeField.Value = 0, 0, Fields!SomeOtherField.Value / IIf(Fields!SomeField.Value = 0, 1, Fields!SomeField.Value))

Open in new window

My formula:
=iif(Fields!optiontype.Value = "BSE",(Fields!basemodelprice.Value - SUM(Fields!BudgetByProduct.Value)) / Fields!basemodelprice.Value, (Fields!amount.Value - SUM(Fields!BudgetByProduct.Value)) / Fields!amount.Value)

Open in new window

Watch Question
Director, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE