Expressions - Please point out my Error

  • Hi All, I'm tearing my hair (what's left of it) out here and cannot figure out what I am doing wrong.

    Using an expression in a tablix

    =IIF((ReportItems!Textbox44.Value)=0,1,2)

    This shows either 1 or 2 correctly but if I change it to

    =IIF((ReportItems!Textbox44.Value)=0,1,2/(ReportItems!Textbox44.Value))

    then I get #Error in the result and the SSRS log shows the following.

    Warning: The Value expression for the textrun ‘Textbox45.Paragraphs[0].TextRuns[0]’ contains an error: Attempted to divide by zero. (rsRuntimeErrorInExpression)

    I've been searching forums for days now with no joy - please help :crying:

  • what is the value for ReportItems!Textbox45.Value for the error rows?

    It could possibly be a null/empty so would not match your IF condition and will then cause a divide by zero error.

    try using IsNothing() as well to check for nulls.

  • Hi Steve

    Thanks for the assist. Sorry but did not work

    The Data is looking like the following

    Textbox43 Textbox44 ExpressionResult

    50 100 50%

    50 0 #Error

    I know that there is actually a value in there and when I remove the divisor, the correct constant value comes up as in

    Textbox43 Textbox44 ExpressionResult

    50 100 200%

    50 0 100%

    BTW Textbox45 contains the expression

    :w00t:

  • Paul Smith-221741 (11/28/2012)


    The Data is looking like the following

    Textbox43 Textbox44 ExpressionResult

    50 100 50%

    50 0 #Error

    I believe it has to do with the order of calculation and that IIF doesn't appear to 'short circuit' the process. Try creating a hidden textbox that'll perform your value manipulation for Textbox44, turning it into a 1 if 0 else leave it alone. Use THAT textbox as your divisor.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • I always get best results when doing division using custom code. Here is an example:

    Public Function CalcRatio(ByVal Numerator As Object, ByVal Denominator As object, ByVal DivZeroDefault As Object) As Object

    If Denominator <> 0 Then

    Return Numerator/Denominator

    Else

    Return DivZeroDefault

    End If

    End Function

    Here is a sample expression for your textbox:

    =code.CalcRatio(Fields!YTDBook.Value, Fields!AnnBudgetRep.Value, 0)

  • @Craig - Thanks works a treat

    @patrick-2 - did the change before seeing yours but will deffo give it a try

    many thanks all

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

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