2
votes

I have a simple SSRS report that displays data from one table. What I want to do is have a distinct list from that table displayed in a drop down list for the user to select. If I only use one dataset I can get it to display, but it displays values from the column multiple times.

Example

Bob
Bob
Bob
Cathy
Cathy

If I create a second dataset that will list distinct values I get the following error message:

An Error occurred during local report processing. The definition of the report is invalid. The Variable expression for the report 'body' refers directly to the field without specifying a dataset aggregate. When the report contains multiple datasets, field references outside of a data region must be contained within aggregate functions which specify a dataset scope.

I"m trying to follow the example I found here: http://msdn.microsoft.com/en-us/library/aa337400.aspx

The second dataset is only for the parameter list. I don't understand why it's causing problems with the actual report.

3

3 Answers

6
votes

It's impossible to tell exactly where without the report definition, but there is an item on the report that is referencing a field or Dataset, and was implicitly using the only Dataset present in the report, but now doesn't know which Dataset to use once more than one is added to the report.

For example, when you create a table you can set a Dataset associated with it. If this is not set and there is only one Dataset, it doesn't matter as it will take the only one available. Once you add a new Dataset, the table doesn't know which one to use and you'll get the error you're seeing.

Another way to get the error is specifying a field in an expression, e.g. in a TextBox in the report somewhere without specifying the scope; just set the scope to a particular Dataset e.g. if you have:

=Count(Fields!name.Value)

change this to:

=Count(Fields!name.Value, "DatasetToUse")

If you've only got one Dataset the first expression will run fine by using the only one available, but once you add another it won't know which to use and it will error.

0
votes

in the query (SQL) you should add DISTINCT clause at the beginning, that way, you will get only one record per value. Check out http://www.w3schools.com/sql/sql_distinct.asp

0
votes

Double click the Dataset which contains that field. Go to fields on the left and delete that field. Add new field by clicking Add -> Query Field. Just type in the name of the new field under field name and field source.

It happens when you have added a field by selecting "Calculated Field" instead of "Query Field" from Dataset Fields list tab.

Cheers, Ahmed Latif