如何获取 SSRS 中特定日期范围之间的列的总和
How to get the sum of a column between a specific date range in SSRS
我正在尝试找到一种方法来获取特定日期范围内的列的总和。
我有一个包含 2016-2019 年数据的数据集,我想使用一个 table 来保存所有四年,以便以后进行交互式排序。我已经为 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)
我需要做什么才能得到表达式来计算日期范围内列中的总金额?
注意:总金额将设置为货币。
您只想将 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
.
进行比较
我正在尝试找到一种方法来获取特定日期范围内的列的总和。 我有一个包含 2016-2019 年数据的数据集,我想使用一个 table 来保存所有四年,以便以后进行交互式排序。我已经为 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)
我需要做什么才能得到表达式来计算日期范围内列中的总金额?
注意:总金额将设置为货币。
您只想将 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
.