简体   繁体   中英

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:

=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. 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

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)

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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