Jonathan Rogers
Jonathan Rogers

Reputation: 31

SSRS Summing Group Variables outside of the group

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

Upvotes: 2

Views: 10292

Answers (3)

Joao Leal
Joao Leal

Reputation: 5542

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.

Upvotes: 2

Jamie F
Jamie F

Reputation: 23809

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

Upvotes: 0

user359040
user359040

Reputation:

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

Upvotes: 0

Related Questions