如何获取SSRS中特定日期范围之间的列总和

时间:2019-05-17 20:00:32

标签: reporting-services expression reportbuilder

我正在尝试找到一种方法来获取特定日期范围之间的列总和。 我有一个数据集,其中包含2016-2019年的数据,并希望使用一张表来保存所有四年的数据,以便以后进行交互式排序。我创建的参数的设置值为1/1 / 201x和12/31 / 201x。

这是我目前正在尝试的操作,但收到错误消息。

=IIF(Fields!TxnDate.Value >= Parameters!start2016.Value AND Fields!TxnDate.Value <= Parameters!end2016.Value, sum(Fields!Amount.Value),0)

错误

System.Web.Services.Protocols.SoapException: The Value expression for the text box ‘Total2016’ 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.
   at Microsoft.ReportingServices.Library.ReportingService2010Impl.CreateReportEditSession(String Report, String Parent, Byte[] Definition, String& EditSessionID, Warning[]& Warnings)
   at Microsoft.ReportingServices.WebServer.ReportingService2010.CreateReportEditSession(String Report, String Parent, Byte[] Definition, String& EditSessionID, Warning[]& Warnings)

我需要怎么做才能使表达式对日期范围内列的总和求和?

注意:总金额将设置为货币。

1 个答案:

答案 0 :(得分:1)

您只想将SUM移到IIF之外。

=SUM(IIF(Fields!TxnDate.Value >= Parameters!start2016.Value AND Fields!TxnDate.Value <= Parameters!end2016.Value, Fields!Amount.Value, 0))

如果金额不是整数,则需要将0转换为带有CDEC(0)的十进制,否则会出现“无法汇总不同类型”错误。

您的日期是文本字符串吗?如果您的评估文本为mm / dd / yyyy格式,则可能无法正常工作。您可能需要转换为日期才能与CDATE进行比较。