Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Divide by Zero frustration Expand / Collapse
Author
Message
Posted Tuesday, January 17, 2012 10:04 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 12:52 AM
Points: 21,385, Visits: 9,601
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
Post #1237358
Posted Sunday, January 22, 2012 1:38 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, May 15, 2014 2:57 PM
Points: 24, Visits: 29
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...
Post #1239959
Posted Thursday, January 26, 2012 1:03 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, April 29, 2014 6:13 AM
Points: 11, 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?
Post #1242425
Posted Friday, January 27, 2012 4:40 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 9:11 AM
Points: 7,128, Visits: 6,291
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1242737
Posted Monday, March 18, 2013 8:52 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Saturday, May 17, 2014 5:41 AM
Points: 93, Visits: 425
=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 ;)
Post #1432218
Posted Tuesday, October 8, 2013 9:46 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 8, 2013 9:45 AM
Points: 3, Visits: 30
Nifty trick....thanks for that.
Post #1502689
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse