none
SSRS expression - Divide second row with first row value in the same column RRS feed

  • Question

  • I have a table with column Account.
    Return 2 value :
    4
    2
    I tried to divide 2/4 using expression
    =Fields!Account.Value/Previous(Fields!Account.Value)

    It works. But it gave an error cell. I think 2/4 and 4/0 (error )

    How do I get rid of the error, just divide 2/4 only
    Please point out what was wrong with it. Many thanks

    Thursday, February 14, 2019 10:22 PM

Answers

  • Hi qplc

    According to your description , seems that in your table , each group instance only have 2 records ,right ?

    If you want the result like below :

    account

    4

    0.5

    2

    0.5

    If so , you could just try to use the expression below :

    =(Last(Fields!Account.Value,”group_name”)/First(Fields!Account.Value,”group_name”))


    Hope it can help you.

    Best Regards,

    Eric Liu


    Best Regards, Eric Liu MSDN Community Support Please remember to click Mark as Answer if the responses that resolved your issue, and to click Unmark as Answer if not. This can be beneficial to other community members reading this thread.

    • Marked as answer by qplc Friday, February 15, 2019 1:07 PM
    Friday, February 15, 2019 3:09 AM

All replies

  • Hi qplc

    According to your description , you want to avoid the Denominator is 0 or nothing , right?

    If so ,you could try  the expression like below:

    =iif(Previous(Fields!Account.Value) is nothing or Previous(Fields!Account.Value) =0 , 0, Fields!Account.Value/Previous(Fields!Account.Value))

    Hope it can help you.

    Best Regards,

    Eric Liu


    Best Regards, Eric Liu MSDN Community Support Please remember to click Mark as Answer if the responses that resolved your issue, and to click Unmark as Answer if not. This can be beneficial to other community members reading this thread.



    Friday, February 15, 2019 1:34 AM
  • Still get error [rsRuntimeErrorInExpression] The Value expression for the textrun ‘Textbox48.Paragraphs[0].TextRuns[0]’ contains an error: Attempted to divide by zero.

    the result is correct but i think still divide 4/0 that why we get error.

    It should get 0.5 only  (2/4)


    • Edited by qplc Friday, February 15, 2019 2:00 AM
    Friday, February 15, 2019 1:58 AM
  • Hi qplc

    According to your description , seems that in your table , each group instance only have 2 records ,right ?

    If you want the result like below :

    account

    4

    0.5

    2

    0.5

    If so , you could just try to use the expression below :

    =(Last(Fields!Account.Value,”group_name”)/First(Fields!Account.Value,”group_name”))


    Hope it can help you.

    Best Regards,

    Eric Liu


    Best Regards, Eric Liu MSDN Community Support Please remember to click Mark as Answer if the responses that resolved your issue, and to click Unmark as Answer if not. This can be beneficial to other community members reading this thread.

    • Marked as answer by qplc Friday, February 15, 2019 1:07 PM
    Friday, February 15, 2019 3:09 AM
  • Yay. Thank you so much. But I wonder if we have third row, then how do we still keep second row divide first row.

    Thank you

    Friday, February 15, 2019 1:09 PM