Wednesday, March 21, 2012

Generating Percent problem with divide by zero

Im trying to generate a percentage value on a agregated field
but in some groups there isn't any information so it tries to divide by zero
and i get an error
So i thought id use a IIf to se if either the Value or the Total was zero
and write out 0 % but the IIf seems to be running the calculation anyway..
heres the code that i'm using as an expression for the percentage field
=IIf(Sum(Fields!MyValue.Value) = 0 Or Sum(Fields!MyTotal.Value) = 0,
0,
SUM(Fields!MyValue.Value) / SUM(Fields!MyTotal.Value)
)
Is this a bug, or is their another way to se that reporting services doesn't
divide by zero?
// LeonHi Leon,
Welcome to use MSDN Managed Newsgroup!
From your descriptions, I understood you would like to know how to aviod
"divide by zero" error by using IIF. If I have misunderstood your concern,
please feel free to point it out.
Based on my knowledge, IIF is a function call and will therefore evaluate
all arguments so it will result in a Division by Zero exception. You may
modify your expression below
=IIf(Fields!MyValue.Value = 0, 0, Fields!MyValue) /
IIf(Fields!MyTotal.Value = 0, 1, Fields!MyTotal.Value)
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

No comments:

Post a Comment