If have a SQL Server Reporting Services report that has several textboxes within a Report with variations of the following expression
=Sum(IiF(Fields!RegisterID.Value = 6000, 1, 0)
and
Iif(Fields!PointID.Value = 500, 1, 0)) / Sum(Iif(Fields!PointID.Value = 500, 1, 0))
I see the following error when I try to preview the report:
The Value expression for the text box ‘Textbox2’ uses an aggregate expression without a scope. A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset.
How do I fix This?
For example, if you do not specify an aggregate for a text box in a group scope, the default aggregate First is used. Each aggregate function topic lists the scopes that are valid for its use. For more information, see Aggregate Functions Reference (Report Builder and SSRS).
As the report processor combines data from a report dataset with the tablix data region, it evaluates group expressions and creates the rows and columns that are needed to represent the group instances. The value of expressions in a text box in each tablix cell is evaluated in the context of the cell scope.
You can specify an aggregate across all group instances. As the report processor combines data from a report dataset with the tablix data region, it evaluates group expressions and creates the rows and columns that are needed to represent the group instances.
These fields are in two different datasets, DataSet1 and DataSet2. The First Function (Report Builder and SSRS), which is an aggregate function, returns the first value of SellStartDate in DataSet1 and the first value of LastReceiptDate in DataSet2.
As per the error, when you are referencing a Dataset field in a textbox that isn't part of a table, you need to specify a Scope for expression, e.g. you want a field, but what Dataset should be used?
So something like:
=Sum(IiF(Fields!RegisterID.Value = 6000, 1, 0), "MyDataset")
Where MyDataset
is the name of a Dataset in your report.
If you are doing this in an independent textbox, you must also use an aggregate function like First
or Sum
, as only one value can be displayed in the textbox and the Dataset might have multiple rows; using an aggregate makes sure only one values is returned, as required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With