ReUsing Expressions

  • If you create an expression for one value on a report can you set that value equal to a variable so that you can reuse the value in another expression on the same report? In Crystal we used Formulas that were reusable in other formulas. Is there a way to do the same in RS?

  • You can use report parameters for this purpose and say they are for internal use.

  • I'm extremly new to RS. Can you give me some more details. Thanks for you reply.

  • Give me a specific problem, then I can provide a step by step solution to it.

    The following is the general procedure to create the parameter.

    Right click on the report and select parameters. Click on Add button and add a parameter. Provide a default value.

    In a textbox that is painted on the screen, use expression - expression builder will appear, select the parameter.

    You can use these parameters to pass to Data portion (as part of sql string or stored procedure parameters etc.,).

    Hope this info sets in right direction.

  • Sorry I was not very clear in my original post. Let me try agian.

    In my data portion of one cell on my report I have an expression like the following:

    Fields!A_data.Value + Fields!B_data.Value

    This gives me a sum of A_data and b_data.

    I now want to reuse the expresion (sum) above without having to reenter the expression over and over in other expressions. In crystal I would have created a formula called @Total and then add the 2 values above together. When I needed that value agian I could have created another formula like so:

    @Total + {data_c}

    this would give me the value of the first formula plus the data_c value as the results. How can I do the same in RS? I hope this is more clear. Thanks for your help.

  • You can just reference the specific report items in SSRS, keeping in mind relative scope. For example, let's say Textbox1 contains the formula: =Fields!data_a.value + Fields!data_b.value. You could just put the following into Textbox2 (if you want to "tack on" the value from the field data_c): =ReportItems!Textbox1.value + Fields!data_c.value.

    The only limitation to this is in regard to the relative scope that I alluded to above. Case in point: when you start using tables with groupings, you can't make a reference in this fashion to a text box that is in a lower level grouping. I.E. referencing a textbox from the details section within a textbox that is located in the group 1 level, for example, will not work.

  • Thanks for the answer. I just found that same reference to ReportItems! that you mentioned just before I read your post.

  • I am wondering if one can write a function to set the value and use it anywhere without the limitation of the scope. Just a thought.

    Dim x as float

    Function setVal(fld1val, fld2Val, returnExistingVal as boolean) as float

    if not returnExistingval then

    x = fld1Val + fld2Val

    end if

    Return (x)

    end function

    Use this function in the textbox2.val = setVal(fld1val, fld2Val, false)

    othertimes use setval(fld1val, fld2val, true).

  • The only problem with a function like this is if the textbox containing the function call (with False for returnExistingVal) is in a table grouping that returns multiple rows.

    For example, if the relevant textbox is in the details row of a table, then this function will be invoked for every line of details data that is returned for the data set in the table.

    And in SSRS, the higher level groupings are rendered/calculated before the lower levels. (Which means that all of the group rows are evaluated before the details rows are.) It becomes a little difficult to manage at that level.

    The beauty of the function in this example is that it does become scope independent. (However, SSRS does evaluate the report elements in a top - down, left - right fashion. So you would need to put the data defining call to the function in a location that puts it at the "top" of the report compared to the other sections that would need to access the value.)

Viewing 9 posts - 1 through 8 (of 8 total)

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