SSRS ISError not working

Hello Experts Exchange
I have a SSRS report that has a table of data and sometime I get an error in my data for the pervious year because there is no data for that year.  I am trying to use ISError to make it to zero but when I run the report it still comes up with #Error, how do I resolve?

This is my script so far;

=IIF(IsError((Fields!AV_TRAN_VALUE_LONG.Value-Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear"))/Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear")),0,(Fields!AV_TRAN_VALUE_LONG.Value-Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear"))/Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear"))

Open in new window


This is my original script before I put ISError on it;

=(Fields!AV_TRAN_VALUE_LONG.Value-Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear"))/Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear"))

Open in new window


How do I resolve the #Error problem.

Regards

SQLSearcher
SQLSearcherAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Koen Van WielinkBusiness Intelligence SpecialistCommented:
Pretty sure you're missing a bracket at the end.
Try this:

=IIF(ISERROR((Fields!AV_TRAN_VALUE_LONG.Value-Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear"))/Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear")),0,(Fields!AV_TRAN_VALUE_LONG.Value-Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear"))/Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear")))

Open in new window

SQLSearcherAuthor Commented:
Hello Koen
There is no problem with the script, the problem lies where I can not capture #Error and convert them to zero.

Regards

SQLSearcher
SQLSearcherAuthor Commented:
Hello Experts Exchange
I found the answer here;
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ef1a0375-414e-41f4-b32f-3b782c5b4c85/error-using-iif-and-divide-by-zero?forum=sqlreportingservices

I had to add some code to the report properties --> properties page --> Code.
Public Function DivideByG(ByVal first As Double, ByVal second As Double) As Double
If second = 0 Then
Return 0
Else
Return (first - second) / second
End If
End Function

Open in new window


I then needed to add to the table this code.

IIF(Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear")= 0, 0, Code.DivideByG(Fields!AV_TRAN_VALUE_LONG.Value, Lookup(Fields!SHOP.Value,Fields!SHOP.Value,Fields!AV_TRAN_VALUE_LONG.Value, "Week_Area_Trans_LastYear")))

Open in new window


Regards

SQLSearcher

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Koen Van WielinkBusiness Intelligence SpecialistCommented:
There you go. Nice find.
Thanks for sharing your solution.
SQLSearcherAuthor Commented:
Found my own solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSRS

From novice to tech pro — start learning today.