Divide by Zero why so difficult?

  • I don't know why it is taking me so long just to figure out something that should be so simple, but anyway, here it is, I just need to keep my expression from kicking out the #error on my report. Here is my expression:

    =Fields!EmailSold.Value+Fields!EmailNotSold.Value\Fields!EmailSold.Value

    This is very simple, I want to add EmailsSold to EmailsNotSold and divide the total amount by EmailsSold to produce a percentage. These are simple integer fields and are not sums of columns. The percentages are not even correct as far as I can tell. OMG Microsoft I can do this calculation in excel in my sleep, why does it seem that SSRS 2008 is overly complicating simple calculations??

    Please someone help me.

  • i created custom code like so:

    Public Shared Function formatDivision(Num1 as double,Num2 as double) as object

    if isnothing(Num2) or Num2 = 0 then

    formatDivision= 0

    elseif isnothing(Num1) or Num1 = 0 then

    formatDivision= 0

    else

    formatDivision= Num1 / Num2 * 100

    end if

    end function

    The Custom Code can be created in the Report Properties section.

    then wrote the value as an expression in the textbox like so:

    =

    Int((

    Code.formatDivision(

    (Sum(Fields!YTD.Value, "dataset"))

    ,

    (Sum(Fields!Jan.Value, "dataset")

    +

    Sum(Fields!YTD.Value, "dataset")

    )

    )

    ))

  • DeanORenO (1/5/2012)


    I don't know why it is taking me so long just to figure out something that should be so simple, but anyway, here it is, I just need to keep my expression from kicking out the #error on my report. Here is my expression:

    =Fields!EmailSold.Value+Fields!EmailNotSold.Value\Fields!EmailSold.Value

    This is very simple, I want to add EmailsSold to EmailsNotSold and divide the total amount by EmailsSold to produce a percentage. These are simple integer fields and are not sums of columns. The percentages are not even correct as far as I can tell. OMG Microsoft I can do this calculation in excel in my sleep, why does it seem that SSRS 2008 is overly complicating simple calculations??

    Please someone help me.

    Your "percentages" aren't correct because your calculation isn't correct. You're missing parentheses around your sum (highlighted below):

    =

    ( <--These are required

    Fields!EmailSold.Value+Fields!EmailNotSold.Value

    ) <--These are required

    \Fields!EmailSold.Value

    Second point. In order to create a percentage - you need to "flip" your expression around (percent sold = # Sold / ( #Sold + #NotSold) and not the other way around). Simply reversing the direction of the / doesn't do that for you.

    ----------------------------------------------------------------------------------
    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?

  • Thank you, I appreciate this help.

  • IIf(Fields!EmailSold.Value = 0, 0, (Fields!EmailSold.Value+Fields!EmailNotSold.Value) \ IIf(Fields!EmailSold.Value) = 0, 1, Fields!EmailSold.Value))

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Here it is, Divide By Zero Handling.. Apply this code in the expression of the textbox...

    =iif(Fields!EmailSold.Value=0,0,(Fields!EmailSold.Value+Fields!EmailNotSold.Value)\Fields!EmailSold.Value)

Viewing 6 posts - 1 through 5 (of 5 total)

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