Reputation: 25775
I'm writing reports on SQL Server Reporting Server that have a number of hours grouped by, say, user, and a total calculated based on the sum of the values.
Currently my query runs a stored proc that returns the hours as in HH:MM format, rather than decimal hours, as our users find that more intuitive. The problem occurs when I try and add up the column using an SSRS expression, because the SUM function isn't smart enough to handle adding up times in this format.
Is there any way to:
I'd like to avoid having to write/run a second query just to get the total.
Upvotes: 2
Views: 11440
Reputation: 11
So in your case its minutes so you need to convert it to seconds , you can try using below code:
=Format(DateAdd("s",(Parameters!ReportParameter1.Value * 60), "00:00:00"),"HH:mm:ss")
Hope this helps
Upvotes: 0
Reputation: 46
You may also try putting this function in your report's custom code.
Function secondsToString(seconds As int64) As String
Dim myTS As New TimeSpan(seconds * 10000000)
Return String.Format("{0:00}:{1:00}:{2:00}",myTS.Hours, myTS.Minutes, myTS.Seconds)
End Function
My SPs generally return time in seconds and this keeps me from having to think too hard if I have to return HH:MM:SS in more than one place. Plus, you can do all of your aggregations normally and wrap them in this to get a pretty format.
I can't take credit for this as I know I stumbled across it on the web some time ago, but I can't recall where.
Upvotes: 2
Reputation: 25775
Answering my own #1:
TimeSpent
below). =FLOOR(Fields!TimeSpent.Value / 60) & ":" & RIGHT("0" & (Fields!TimeSpent.Value MOD 60), 2)
=FLOOR(Sum(Fields!TimeSpent.Value) / 60) & ":" & RIGHT("0" & (Sum(Fields!TimeSpent.Value) MOD 60), 2)
Upvotes: 4