Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Divide by Zero frustration


Divide by Zero frustration

Author
Message
Brandie Tarvin
Brandie Tarvin
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7804 Visits: 8745
It doesn't seem to matter how I word this my Expression, I keep getting the following error: "rsRuntimeErrorInExpression The value expression for the textbox contains an error: Attempted to divide by zero.".

I've tried this:

=IIF((Fields!NbrClaims.Value)> 0 and (Fields!NbrClaims.Value)< 0,
Round((First(Fields!PaidClaims.Value)/
First(Fields!NbrClaims.Value)),2), "0.00")



And this:

=IIF((Fields!NbrClaims.Value)<> 0,
Round((First(Fields!PaidClaims.Value)/
First(Fields!NbrClaims.Value)),2), "0.00")



and this:

=IIF((Fields!NbrClaims.Value)= 0, "0.00",
Round((First(Fields!PaidClaims.Value)/
First(Fields!NbrClaims.Value)),2))



and I've even put a NULL test in there, even though the results of my original dataset always come back with zeros not nulls. And I still get the stupid "Divide by Zero" error. SSRS doesn't seem to be parsing the IIF right. And if I take the quotes off the 0.00, it still doesn't make a difference.

Can anyone see what I'm missing? I'm getting really annoyed. The error only happens on the one line with zeros on it. The code works for every other group line.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Matt Miller (#4)
Matt Miller (#4)
SSCertifiable
SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

Group: General Forum Members
Points: 7643 Visits: 18084
IIF is going to eval BOTH parts (the THEN and the ELSE) even if it returns just one.

Try this instead:

= Round(
First(Fields!PaidClaims.Value)/
IIF(First(Fields!NbrClaims.Value)=0,
1,
First(Fields!NbrClaims.Value)
)
,2)



----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Brandie Tarvin
Brandie Tarvin
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7804 Visits: 8745
Matt,

You're da bomb! Thanks, that worked perfectly.

Don't know what I'd ever do without you. @=)

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
toolman-352714
toolman-352714
SSC-Enthusiastic
SSC-Enthusiastic (147 reputation)SSC-Enthusiastic (147 reputation)SSC-Enthusiastic (147 reputation)SSC-Enthusiastic (147 reputation)SSC-Enthusiastic (147 reputation)SSC-Enthusiastic (147 reputation)SSC-Enthusiastic (147 reputation)SSC-Enthusiastic (147 reputation)

Group: General Forum Members
Points: 147 Visits: 712
Another option (especially if you've got a report with many expressions that could result in divide by zero situations is to use a Custom Code function.

In the Code tab/window of Report Properties, enter something like the following:

Public Function DivideBy(ByVal Exp1, ByVal Exp2)
If Exp2 = 0 Then
DivideBy = 0
Else : DivideBy = Exp1 / Exp2
End If
End Function

Then insert the expression
=code.DivideBy(Field!ToBeDivided.Value,Field!DividingBy.Value)
into any cell that has the potential for divide by zero problems.

toolman
Numbers 6:24-26
Brandie Tarvin
Brandie Tarvin
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7804 Visits: 8745
Now there's a nifty piece of code I need to book mark. Thanks, toolman!

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
cavo789
cavo789
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 93
Exactly what I was searching for. Thanks a lot ! Wink

Christophe

Christophe
jessica 41729
jessica 41729
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 7
You just saved me hours of work.

Thanks!
Ninja's_RGR'us
Ninja's_RGR'us
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20937 Visits: 9671
If RS is a pretty big PITA in that regard. The problem with that function is that you need to copy it everywhere and it slows down execution. I wish that the IIF could short-circuit and not throw this useless error. More to the point I think everyone using RS has had this issue!
dev.mail2ray
dev.mail2ray
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 20
Try this.

= Fields!A.Value / IIF(Fields!B.Value=0,1,Fields!B.Value)
:-)
pnelson 10021
pnelson 10021
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 95
I have this expression and haven't been able to eliminate the divide by zero error. I also tried creating custom code but the examples I've seen as far as where to put the code.divideby don't seem to work with this expression.
The issue is with the part that is bolded
Can anyone help with this?

=((Sum(Fields!field3.Value) / Sum(Fields!field1.Value) * 10 + Sum(Fields!field4.Value) / Sum(Fields!field1.Value) * 10 + Sum(Fields!field5.Value) / Sum(Fields!field1.Value) * 10 + Sum(Fields!field6.Value) / Sum(Fields!field1.Value) * 10) - (Sum(Fields!field7.Value) / Sum(Fields!field2.Value) * 10 + Sum(Fields!field8.Value) / Sum(Fields!field2.Value) * 10 + Sum(Fields!field9.Value) / Sum(Fields!field2.Value) * 10 + Sum(Fields!field10.Value) / Sum(Fields!field2.Value) * 10)) / (Sum(Fields!field7.Value) / Sum(Fields!field2.Value) * 10 + Sum(Fields!field8.Value) / Sum(Fields!field2.Value) * 10 + Sum(Fields!field9.Value) / Sum(Fields!field2.Value) * 10 + Sum(Fields!field10.Value) / Sum(Fields!field2.Value) * 10)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search