Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping formula from returning DIV/0 or #Num! error 1

Status
Not open for further replies.

CMooreJr

Technical User
Feb 20, 2003
217
US
Hey all! I have a report with 2 fields,

"UnitsSold" and "PrevTotSold"

I need to calculate the percentage of change in these fields. I have created a textbox with the control source..
=([UnitsSold]-[PrevTotSold])/[PrevTotSold] set as a percent. This works great if there are units sold and previous units, but if [PrevTotSold] happens to be 0, then I get a Div/0 error. This should really be 100 percent. If the [UnitsSold] is zero, I get a #Num! error..this should be 0%. How can I say Div/0=100% and #Num!=0%

or is there a better way to do it??

Thanks for your help!!!!
 
A nested IIf statement should work, checking for these boundary conditions.
=IIf(([UnitsSold]=0),0,IIf(([PrevTotSold]=0),100,([UnitsSold]-[PrevTotSold])/[PrevTotSold]))

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top