简体   繁体   English

如何在SSRS中获取开始日期和结束日期之间的差的平均值

[英]How to get the average of the difference between start date and end date in SSRS

While trying to use reporting services I have tried to include a calculation. 在尝试使用报表服务时,我尝试进行计算。 The calculation I'm trying to find is the average of the difference between the start date and the end date of every record. 我要查找的计算是每条记录的开始日期和结束日期之间的差的平均值。

I'm trying this piece of code in SSRS: 我正在SSRS中尝试这段代码:

=CInt(DateDiff(DateInterval.Day, CDate(First(Fields!StartDate.Value, "DataSet1")), CDate(First(Fields!EndDate.Value, "DataSet1")))) / COUNTDISTINCT(DataSet1.Fields!Forename.Value)

But this comes out with the error 但这出了错误

The Value expression for the text box 'Textbox31' uses an aggregate expression without a scope. 文本框'Textbox31'的Value表达式使用不带范围的聚合表达式。 A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset. 除非报告中仅包含一个数据集,否则在数据区域外使用的所有聚合都需要一个范围。

In your sql select statement input: DATEDIFF(d, StartDate, EndDate) AS daysdiff 在您的sql select语句中输入:DATEDIFF(d,StartDate,EndDate)AS daysdiff

then in your report designer (either add total within a table or as a column in a matrix) use this expression 然后在报表设计器中(将总计添加到表中或作为矩阵中的列)使用此表达式

=Avg(Fields!daysdiff.Value) = AVG(字段!daysdiff.Value)

It seems that your doing this in a text box and not a table. 看来您是在文本框而不是表格中执行此操作。

Since the text box does not have it's own dataset property, you need to specify the dataset in your expression. 由于文本框没有它自己的数据集属性,因此需要在表达式中指定数据集。 You have it all of the except the COUNT. 您拥有除COUNT以外的所有内容。

=DateDiff(DateInterval.Day, CDate(First(Fields!StartDate.Value, "DataSet1")), CDate(First(Fields!EndDate.Value, "DataSet1"))) / COUNTDISTINCT(DataSet1.Fields!Forename.Value, "DataSet1")

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

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