Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create report textbox aggregate expression in SQL server reporting with multiple datasets

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?

like image 822
Fozzy767 Avatar asked Jan 29 '14 17:01

Fozzy767


People also ask

What if I do not specify an aggregate for a textbox?

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).

How are group expressions evaluated in tablix data region?

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.

Can I specify an aggregate across all group instances in tablix?

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.

What are the dataset1 and dataset2 fields in SSRs?

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.


1 Answers

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.

like image 160
Ian Preston Avatar answered Oct 16 '22 21:10

Ian Preston