SSRS Summing Group Variables outside of the group

前提是你 提交于 2021-02-10 11:46:23

问题


I have succeeded in building a number of group variables within an SSRS report, however what I want to do now is to use that variable outside of the group.

eg - I have a variable that calculates a payment within one dataset, and another one that calculates a payment within another dataset.

The first would be =Variables!QualityPayment.Value, the second would be =Variables!RevenuePayment.Value. Revenue and Quality are displayed in different SSRS tables.

I want to add the Quality Payment and Revenue Payment together, but when I try and put them outside of the table I get the error message

'Expressions can only refer to a Variable declared within the same grouping scope, a containing grouping scope, or those declared on the report.'

How do I go about adding the two together?

Thanks in advance

Jon


回答1:


What I would do would be to use the group variable just as a way to add the values to an external variable, declared on the VB Code section of the report:

On the Report Properties -> Code section you use the following code:

Dim variable1 AS Integer
Function addValue(ByVal value AS Integer)
    variable1 += value
End Function

Function getValue()
    return variable1
End Function

Then on the group variable section of the tablix, you just call addValue(somefield) and when you need to access the calculated value you can do it from outside the group by calling the getValue function.




回答2:


Assuming that both datasets are accessing the same database, I suggest combining the two datasets into a single dataset.




回答3:


In your definition of the variables, make sure that any aggregate functions have the dataset specified for the scope, i.e.:

=SUM(Fields!MyFieldName.Value, "DataSet1") / 12


来源:https://stackoverflow.com/questions/8298799/ssrs-summing-group-variables-outside-of-the-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!