SSRS error - A scope is required for all aggregates in the page header or footer which reference fields

dba.stackexchange https://dba.stackexchange.com/questions/142413

  •  02-10-2020
  •  | 
  •  

Question

I had the following textbox expression in my SSRS report and it was working fine.

  = First(Fields!FirstName.Value) +" " + First(Fields!LastName.Value) + ", MD"

When I moved the textbox to the report header area I started getting the "scope required" error message

I did some research and saw that I needed to specify the dataset. Once I included the dataset (PPR) below the error went away.

  = First(Fields!FirstName.Value,"PPR") +" " + First(Fields!LastName.Value, "PPR") + ", MD"

SSRS is now giving the same error but for another textbox/expression (below) that was working fine until I moved it to the header.

="Interim Score:   " & CINT((sum(CINT(left(fields!Points.value,1))) / sum(CINT(right(fields!Points.value,1))))*100) & "%"

I tried the following 2 modifications to include the scope (PPR) in the expression but I am still getting the same error. Is this just a syntax error on my part or am I trying to do something that can't be done in the header?

didn't work

="Interim Score:   " & CINT((sum(CINT(left((fields!Points.value,"PPR"),1))) / sum(CINT(right((fields!Points.value,"PPR"),1))))*100) & "%"

didn't work

="Interim Score:   " & CINT((sum(CINT(left(fields!Points.value,"PPR",1))) / sum(CINT(right(fields!Points.value,"PPR",1))))*100) & "%"

Below is the full error message I am getting:

The Value expression for the text box ‘Textbox6’ references a field in an aggregate expression without a scope. A scope is required for all aggregates in the page header or footer which reference fields.

I only have 1 dataset (PPR) in my report.

I was reading up on the below page but I can't seem to pinpoint what I am doing wrong. Any suggestions would be greatly appreciated.

https://technet.microsoft.com/en-us/library/dd220421%28v=sql.110%29.aspx

Was it helpful?

Solution

The reason I was getting the error message is because I was supplying the scope (dataset) in the wrong place.

The scope needs to be supplied as the second argument of the aggregate function. I was incorrrectly supplying the scope as part of the left function (which is not an aggregate function) instead of the SUM function.

Below is what the working expression looks like. The only difference from my original syntax is the location of the scope/dataset name (PPR) in the expression.

="Interim Score:   " & CINT((sum(CINT(left(fields!Points.value,1)),"PPR") / sum(CINT(right(fields!Points.value,1)),"PPR"))*100) & "%"
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top