【问题标题】:How to get the sum of a column between a specific date range in SSRS如何获取SSRS中特定日期范围之间的列的总和
【发布时间】:2019-05-17 20:00:31
【问题描述】:

我正在尝试找到一种方法来获取特定日期范围之间的列的总和。 我有一个数据集,其中包含 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)

我需要做什么才能让表达式对日期范围内列中的总金额求和?

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

【问题讨论】:

  • 正如汉诺威指出的那样,IIF/SUM 表达式不正确,但您得到的错误是范围错误。你把这个表达式放在哪里?它是在表格/矩阵中还是仅在文本框中?如果它只是在文本框中,则需要根据要评估的内容添加范围,如果要对整个数据集进行求和/iff,则使用引号中的数据集名称作为范围 =SUM(IIF(Fields!X.Value &gt; Parameters!myParameterName.Value, Fields!myValue.Value, 0), "myDataSetName")

标签: reporting-services expression reportbuilder


【解决方案1】:

您只想将 SUM 移到 IIF 之外。

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

如果您的金额不是整数,则需要使用 CDEC(0)0 转换为小数,否则您会收到无法聚合不同类型的错误。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 2014-08-17
    相关资源
    最近更新 更多