错误:指定数据集范围的嵌套聚合

时间:2016-01-08 09:19:28

标签: reporting-services ssrs-2008-r2 ssrs-2012

我一直在研究ssrs,并尝试做以下声明。我正在使用来自2个数据集的数据,我无法将它们合并为一个(我第一次遇到此错误时尝试过)。代码:

=Sum(iif(Fields!Year.Value = Max(Fields!Year.Value) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0))

此代码提供错误:The Value expression for the text box has a nested aggregate that specifies a dataset scope. Inner aggregates cannot specify a dataset scope.

我还试过这个代码的不同变体,如下所示:

=(iif(Fields!Year.Value = Max(Fields!Year.Value) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0))

我刚刚摆脱了总和。但这次我有一个不同的错误:Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope. Letters in the names of fields must use the correct case

希望有人可以提供帮助:)

干杯

1 个答案:

答案 0 :(得分:1)

你的表达有点不对劲。

=Sum(iif(Fields!Year.Value = Max(Fields!Year.Value) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0))

您的 Sum 在外面,并且涵盖了不在同一数据集中的两个字段。您应为每个人分配 Sum ,因为它们来自不同的数据集。

试试这个:

=iif(Sum(Fields!Year.Value) = Max(Sum(Fields!Year.Value)) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0)

注意:如果这是正确的,我还没有对Max(Sum(....进行测试。