SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Divide by Zero frustration


Divide by Zero frustration

Author
Message
Ninja's_RGR'us
Ninja's_RGR'us
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65111 Visits: 9671
SSRS is annoying with that.

Use this code to do the division (rename as you wish, this is not Ms Access after all! ;-)).

PUBLIC FUNCTION NDZ(Numerator, Denominator, DZResult)
IF Denominator = 0 THEN
RETURN DZResult
ELSE
RETURN Numerator / Denominator
END IF
END FUNCTION
ansuman2006
ansuman2006
SSC-Enthusiastic
SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)

Group: General Forum Members
Points: 149 Visits: 53
My problem was to display zero if the value of the denominator is zero, else the division of the two fields.
So what I used is mentioned below,

iff(Field2=0,0,Field1/Field2)

I worked.. Hope it does the same for you all... :-)
jacksoncc
jacksoncc
SSC-Enthusiastic
SSC-Enthusiastic (119 reputation)SSC-Enthusiastic (119 reputation)SSC-Enthusiastic (119 reputation)SSC-Enthusiastic (119 reputation)SSC-Enthusiastic (119 reputation)SSC-Enthusiastic (119 reputation)SSC-Enthusiastic (119 reputation)SSC-Enthusiastic (119 reputation)

Group: General Forum Members
Points: 119 Visits: 409
@penelson
re:
=((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)

shouldn't the operand before Sum(Fileds!field7.Value) be a '+' sign?
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36401 Visits: 9268
All,

I received my answer to this question a long time ago. If you need assistance with a similar problem, please start a new thread as you are more likely to get responses to your question if you post in a thread that doesn't have pages of answers or a thread which says "Problem Solved" in the third or fourth post.

Not a lot of people are going to read beyond my comment of "problem solved."

This is just a friendly public service announcement.

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.
christian_t
christian_t
Say Hey Kid
Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)Say Hey Kid (669 reputation)

Group: General Forum Members
Points: 669 Visits: 531
=IIf(
IsNothing(Sum(Fields!divisor.Value)) Or Sum(Fields!divisor.Value) = 0.0,
"",
Sum(Fields!value.Value) / IIf(IsNothing(Sum(Fields!divisor.Value)) Or Sum(Fields!divisor.Value) = 0.0, 1, Sum(Fields!divisor.Value))
)

I just wanted to add a fact:
If you have a division, that does not allow you to use the divisor "1" instead of "Nothing" you can still use the suggested solutions in this tread:

What you have to do is use your conditions twice: first your "old" way: IIf(Sum(Fields!divisor.Value) = 0.0, "", ...
Then in the dvision: ...Value) / IIf(IsNothing(Sum(Fields!divisor.Value)) Or Sum(Fields!divisor.Value) = 0.0, 1, Sum(...

As you can see, you still have a divsion by 1 implemented but it can never be reached as you ruled it out before.
That makes the renderer and you happy Wink
andres.jordan
andres.jordan
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 31
Nifty trick....thanks for that.
ashok_k_ghattamaneni
ashok_k_ghattamaneni
SSC Journeyman
SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)

Group: General Forum Members
Points: 88 Visits: 44
I tried this approach. it ddn't work for me. please help me..

Public Function Divider (ByVal Dividend As Double, ByVal Divisor As Double)
If IsNothing(Divisor) Or Divisor = 0
Return 0
Else
Return Dividend/Divisor
End If
End Function

=Code.Divider(cstr(cint(Sum(Fields!DRGMatch.Value),CountDistinct(Fields!LocalID.Value+Fields!UIUserID.Value)*100)))+"%"

got the below Error:

Textbox16.Paragraphs[0].TextRuns[0]’ contains an error: [BC30198] ')' expected._
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36401 Visits: 9268
ashok_k_ghattamaneni (9/22/2014)
I tried this approach. it ddn't work for me. please help me..

Public Function Divider (ByVal Dividend As Double, ByVal Divisor As Double)
If IsNothing(Divisor) Or Divisor = 0
Return 0
Else
Return Dividend/Divisor
End If
End Function

=Code.Divider(cstr(cint(Sum(Fields!DRGMatch.Value),CountDistinct(Fields!LocalID.Value+Fields!UIUserID.Value)*100)))+"%"
got the below Error:

Textbox16.Paragraphs[0].TextRuns[0]’ contains an error: [BC30198] ')' expected._


My guess is that you have a paren in the wrong place. Check the bolded text and play around with where the parens should be.

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.
jsm60
jsm60
Valued Member
Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)

Group: General Forum Members
Points: 59 Visits: 99
Matt and toolman - Thanks, I needed this!
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