2
votes

I am creating a variable trying to use a field from a dataset, but it's throwing an error. "DATAFields" is the name of the dataset.

=Year(Fields!Year.Value, "DATAFields")-9

Error:

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

Example
02/02/2015 
Output 
2007

Please can someone help...

3
Please post the complete error message. and include in your question an example of your desired output. - bot

3 Answers

1
votes

I have used a Parameter to reference. and it now works.

=Year(Variables!Short_Month.Value)-9

In the textbox I used

=Variables!v1.Value & " Total is"
0
votes

Since in your question you are using a dataset name I assume you are calling dataset1 from dataset2. And you are trying to get the year from that field in dataset1.

This expression is wrong:

=Year(Fields!Year.Value, "DATAFields")-9

You try this:

=First(Fields!Year.Value, "DATAFields")
  • right click on the expression > Placeholder Properties > Number > Date > Choose your desired date format.

*If ever you are not calling it from another dataset you could just use:

=Fields!Year.Value

Then repeat how to format your date.

*Note: There is another way to format your date in your expression but for me this a bit cleaner way.

UPDATE: You could also try this:

=Year(First(Fields!DatePreparedBy.Value, "DSBUser"))-9 & " Total is"
0
votes

I had the same problem. If your report has more than one dataset, you cannot use the "first()" function in a variable expression.

I also didn't want to pass the value as a parameter. I ended up creating a calculated field in the same dataset as the data I was trying to reference and that worked for me.