简体   繁体   English

SSRS表达式:文本框的值表达式具有范围参数,该参数对于聚合无效

[英]SSRS Expression: The value expression for textbox has scope parameter that is invalid for aggregate

i'm recieving the following error: 我收到以下错误:

Error   1   [rsInvalidAggregateScope] The Value expression for the text box 
‘Textbox2’ has a scope parameter that is not valid for an aggregate function.  
The scope parameter must be set to a string constant that is equal to either 
the name of a containing group, the name of a containing data region, or 
the name of a dataset.

The expression behind my Textbox2 (i've added some spaces for readability): 我的Textbox2后面的表达式(为可读性添加了一些空格):

Iif(Parameters!ReportParameterPersoneelsNr.Value.Equals(String.Empty),

       "Prestaties " + First(Fields!firmanaam.Value, "DataSetHrm") + 
        "(" + First(Fields!indienstfirmanr.Value, "DataSetHrm") + ")",

       "Prestaties " + First(Fields!naam.Value, "DataSetHrm") + " " +
       First(Fields!voornaam.Value, "DataSetHrm") + 
       "(" + First(Fields!personeelsnr.Value, "DataSetHrm") + ")")

The fields: 田野:

      ReportParameterPersoneelsNr = Reportparameter of type Text
      firmanaam.Value = VARCHAR
      indienstfirmanr.Value = Long
      naam.Value = VARCHAR
      voornaam.Value = VARCHAR
      personeelsnr.Value = Long

Searches on Stackoverflow brought me following results. 在Stackoverflow上进行的搜索为我带来了以下结果。 But so far they haven't helped me solve my problem 但是到目前为止,他们还没有帮助我解决我的问题

Post 1: what-does-scope-parameter-that-is-not-valid-for-an-aggregate-function-mean 发布1:范围参数对汇总功能的含义无效

Post 2: SqlTeam 帖子2:SqlTeam

Could someone point out what i'm doing wrong? 有人可以指出我在做什么错吗?

Note : Adding tostring() everywhere didn't help 注意 :在各处添加tostring()并没有帮助

Note 2 : Replacing the '+' with '&' didn't resolve the issue either 注意2 :用'&'代替'+'也不能解决问题

Note 3 : The datasetname is correct and the dataset is the only one present in this SSRS report: 注3 :数据集名称正确,并且该数据集是此SSRS报告中唯一的数据集:

图像Tds

Update: The data contained by the dataset is valid and readding the dataset did not work (tried with and without aliases) 更新:数据集包含的数据有效,并且读取数据集无效(尝试使用别名和不使用别名)

Sometimes this error occurs while we use different DatasetName in Experssion . 有时在Experssion使用不同的DatasetName时会发生此错误。

Like in my case I have solved this error by doing below thing, 就我而言,我通过做以下事情解决了这个错误,

Before it was like below, 像下面这样

="For Man " + 
   IIF(Len(First(Fields!Lname.Value, "DataSet1")) > 0,
   First(Fields!Lname.Value, "DataSet1"),"") & IIF(Len(First(Fields!Fname.Value, "DataSet1")) > 0,
   ", " + First(Fields!Fname.Value, "DataSet1"),"")

After changed it to below it is working fine now, 将其更改为以下值后,现在可以正常使用了,

="For Man " + 
    IIF(Len(First(Fields!Lname.Value, "LastChangedDataSetName")) > 0,
    First(Fields!Lname.Value, "LastChangedDataSetName"),"") & IIF(Len(First(Fields!Fname.Value, "LastChangedDataSetName")) > 0,
    ", " + First(Fields!Fname.Value, "LastChangedDataSetName"),"")

Note: So here the mistake was I have changed the DataSet Name From DataSet1 to LastChangedDataSetName and remained to change that name in last Expression that I have already written before changing DataSet Name . 注意:所以这里的错误是我已将DataSet名称DataSet1更改为LastChangedDataSetName并且仍然要更改我在更改DataSet Name之前已经编写的最后一个Expression中的名称

I don't know what is wrong, but have created a similar report that works. 我不知道出什么问题了,但是创建了一个类似的报告。 Create a new blank report, then create a dataset (from SQL Server) with following query: 创建一个新的空白报告,然后使用以下查询创建一个数据集(来自SQL Server):

SELECT 'ACME' AS firmanaam, 10000 AS indienstfirmanr, 'Doe' AS naam, 'Jon' AS voornaam, 987654 AS personeelsnr 选择'ACME'AS公司,anad 10000 AS,'Doe'公司naam,'Jon'公司voornaam,987654 AS personeelsnr

数据集图片

Then add your parameter 然后添加您的参数

参数定义

Add a textbox to the report, with code: 使用代码将文本框添加到报告中:

= Iif(Parameters!ReportParameterPersoneelsNr.Value.Equals(String.Empty), "Prestaties " & First(Fields!firmanaam.Value, "DataSetHrm") & "(" & First(Fields!indienstfirmanr.Value, "DataSetHrm") & ")", "Prestaties " & First(Fields!naam.Value, "DataSetHrm") & " " & First(Fields!voornaam.Value, "DataSetHrm") & "(" & First(Fields!personeelsnr.Value, "DataSetHrm") & ")")

Then run the report with or without a value for the parameter: 然后运行带有或不带有参数值的报告:

报告预览

空参数预览

I faced a similar issue recently in one of my reports. 我最近在一份报告中遇到了类似的问题。 The reason I have this error is that the name of the data set and the expression in the report do not match. 我出现此错误的原因是数据集的名称和报表中的表达式不匹配。

I have a date field which is populated with User preferences and the expression is First(Fields!column.Value, "datasetname") . 我有一个用用户首选项填充的日期字段,表达式是First(Fields!column.Value, "datasetname") The dataset name and the dataset name specified in reports data should match. 报告数据中指定的数据集名称和数据集名称应匹配。

The error I had in my report was very similar: 我在报告中遇到的错误非常相似:

Error 1 [rsInvalidAggregateScope] The Hidden expression for the tablix 'table1' has a scope parameter that is not valid for an aggregate function. 错误1 [rsInvalidAggregateScope] tablix'table1'的隐藏表达式的范围参数对于聚合函数无效。 The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset. 必须将scope参数设置为一个字符串常量,该常量等于包含组的名称,包含数据区域的名称或数据集的名称。

I solved it by right clicking the report file in Solution Explorer + View Code (opens the XML editor), searching for the name of the report's main DataSet and changing the line that caused the problem: 我通过在解决方案资源管理器 + 查看代码中右键单击报告文件(打开XML编辑器),搜索报告主数据集的名称并更改引起问题的行来解决此问题:

<TablixMember>
  <Visibility>
    <Hidden>=iIF(CountRows("MYDATASETNAME") = 0, false, true)</Hidden>
  </Visibility>
  <KeepTogether>true</KeepTogether>
</TablixMember>

In this case, I just needed to alter the expression inside the <Hidden> tag which had a name of a non existing DataSet (due to copying from another report). 在这种情况下,我只需要更改<Hidden>标记内的表达式,该标记的名称不存在(由于从另一个报表复制而来)。 Later on, it was easier to locate the row in the interface that caused the error. 稍后,在导致错误的界面中查找行更加容易。

Therefore if the error refers to Value instead, search for occurrences of the report's DataSet name in the XML code and double check the <Value> tags for names that do not exist in the current report. 因此,如果错误代之以Value ,请在XML代码中搜索该报表的DataSet名称的出现,然后仔细检查<Value>标记以查找当前报表中不存在的名称。

Your scope reference is not proper ("DataSetHrm"). 您的范围引用不正确(“ DataSetHrm”)。 As the error message states from a textbox can only a containig scope referenced that can be a group in a table (scope name = group name), the table itself (data region -> scope name = data region name) or the dataset that belongs to a data region (scope name = dataset name). 由于错误消息来自文本框,因此只能引用一个containig作用域,该作用域可以是表中的组(作用域名称=组名称),表本身(数据区域->作用域名称=数据区域名称)或属于的数据集到数据区域(作用域名称=数据集名称)。

When these regions mentioned above are embedded stating with the dataset (dataset -> data region -> data group), they can be referenced from a textbox. 当上面提到的这些区域与数据集一起嵌入时(数据集->数据区域->数据组),可以从文本框中引用它们。 In your example this is not the case. 在您的示例中,情况并非如此。

If you want to use another dataset in your textbox which differs from your actual dataset (which is the dataset of your table), you have to use the lookup() function. 如果要在文本框中使用与实际数据集(表的数据集)不同的另一个数据集,则必须使用lookup()函数。

This is quite often caused when replacing one stored procedure w/ another. 这是在替换带有另一个存储过程时经常引起的。 This comes up quite a lot when you are making a derivative of a report (maybe a quarterly report instead of a monthly) and you make a new sp that is similar but different. 当您生成报表的派生词(可能是季度报表,而不是每月报表),并且生成的新sp相似但又不同时,这会出现很多。

It is not necessary to rename the dataset. 不必重命名数据集。 Doing so can often cause problems that are very hard to diagnose. 这样做通常会导致很难诊断的问题。

The nature of the report editor is very clicky and dialogue intensive. 报表编辑器的性质非常棘手,并且需要大量对话。 Its almost impossible to find the problem by clicking around on the report canvas and looking for the offending problem. 通过在报表画布上单击并查找有问题的问题来几乎找不到问题。

It would be easy for MS to show the offending expression editor immediately after showing the message complaining about the expression. MS在显示抱怨该表达式的消息后立即显示有问题的表达式编辑器很容易。 The editor is not very good, but MS seemingly has little incentive to make it better. 编辑器不是很好,但是MS似乎没有动力去做得更好。

Suggestion 1 To stay out of trouble - name your main dataset DATA1 or something similar. 建议1为避免麻烦-命名主数据集DATA1或类似名称。 If you change the SP, leave the dataset name alone. 如果更改SP,请不要使用数据集名称。

Suggestion 2 to stay out of trouble - If you are making a copy of a report and want to keep the tablix, consider making the new SP add columns. 建议2避免麻烦-如果您要制作报表的副本并希望保留Tablix,请考虑制作新的SP添加列。 Dont remove any, even if they are null. 即使它们为空,也不要删除任何内容。 Sometimes this is possible, sometimes it is not. 有时这是可能的,有时则不是。

Suggestion 3 - If you are in trouble and want out - save the report as an RDL on your desktop and open it with notepad. 建议3-如果遇到麻烦并想要退出-将报告另存为RDL在桌面上,并使用记事本打开它。 Search for "Fields!". 搜索“字段!”。 This should lead you to the expression(s) that is causing the problem. 这应该导致您导致问题的表达式。

Also look for the old dataset name if you changed it. 如果您更改了旧数据集的名称,还请查找它。 Also look for fields omitted in the new dataset if there are any 如果有的话,还要寻找新数据集中省略的字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM