Getting a #Error with Expression When Dividing 0 by 0

  • Greeting,

    I have the following expression that is return #Error when the data contains a 0/0. I have tried several changes to the expression, no of which worked - UGH. Any suggestions would be helpful.

    = IIF(Fields!Presentations.Value = 0, "00:00:00", Format(DateAdd("s", (Fields!TalkTimeSeconds.Value/Fields!Presentations.Value), "00:00:00"), "HH:mm:ss"))

    Thank you,
    Cervello

  • Hello,

    I have a thought on this.  Is it an error when Presentations has a value of 0 or when it is null?  You may want to also check for null values as dividing by null I think will give you an #Error as well.
    The other thing I can think of is what does the error window say?  It usually tells you what was wrong if something is wrong.

    For debugging purposes, you could change your IIF to:
    =IIF(Fields!Presentations.Value=0,0,1)

    that way you can determine what is wrong.  It will tell you which rows are seeing the value as 0 and what rows are seeing it as non-zero.
    Also, what is the datatype on Presentations?  If it is not an int or a derivitive of int, comparing it to the integer 0 will return false I believe.  That is, I am fairly confident that SSRS sees 0 and "0" (integer vs string) as different values.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

  • Thank you for getting back to me.
    I found the solution and wanted to share in case any one else comes across this issue.

    use the following code resolves the issue of dividing by zero OR dividing zero by zero.

    =IIF(Fields!Presentations.Value > 0, Format(DateAdd("s", (Fields!TalkTimeSeconds.Value/
    IIF(Fields!Presentations.Value > 0, Fields!Presentations.Value,1)),"00:00:00"),"HH:mm:ss"), "00:00:00")

    Thank you,
    Cervello

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply