简体   繁体   English

SSRS平均时间(分钟),然后格式化为HH MM

[英]SSRS Average Time in Minutes and then Format to HH MM

I've seen a lot of questions about average time in SSRS but I'm pretty new to this and none of these questions address my specific need so any help would be appreciated. 我已经看到很多有关SSRS平均时间的问题,但是我对此很陌生,这些问题都不能满足我的特定需求,因此我们将不胜感激。

I have a duration field (Fields!Duration1.Value) which is pulling in a duration in minutes (example: 170). 我有一个持续时间字段(Fields!Duration1.Value),以分钟为单位(例如:170)。 In my stored procedure I'm converting this to HH MM like so: 在我的存储过程中,我将其转换为HH MM,如下所示:

CONVERT(VARCHAR(5),DATEADD(minute, test.Duration,0) ,114) AS Duration1

This is working like a charm and I'm using it in my SSRS report. 这就像一种魅力,我在SSRS报告中正在使用它。 Unfortunately, I also have need of getting an average duration. 不幸的是,我也需要获得平均时长。 So I threw in the original field test.Duration as an extra SELECT in my stored procedure. 因此,我在存储过程中添加了原始的字段test.Duration作为额外的SELECT。 The report is set up as a matrix and so it is the "total" line where I want to have the average displayed. 该报告设置为矩阵,因此它是我希望显示平均值的“总计”行。

So I'm pretty sure I need to first: 所以我很确定我需要先:

=Avg(Fields!test.Duration.Value)

Which works (but has a ridiculous decimal value), but how do I then Format that value back to HH:MM??? 哪个有效(但有一个荒谬的十进制值),但是我该如何将该值格式化回HH:MM? I'm sure I could do this in my stored procedure but I'm not positive on how to do it there either so basically: any and all help welcome! 我敢肯定我可以在存储过程中做到这一点,但是基本上我对如何做到这一点都不满意:欢迎任何帮助!

Thanks 谢谢

You could add your own formatting function to the Report Code section: 您可以将自己的格式设置功能添加到“报告代码”部分:

Public Function MinsToHHMM (ByVal Minutes As Decimal)
  Dim HourString = Floor(Minutes/60).ToString() 
  Dim MinString = Floor(Minutes Mod 60).ToString()
  Return HourString.PadLeft(2, "0") & ":" & MinString.PadLeft(2, "0")
End Function 

and then call it in the cell expression like this: 然后在像这样的单元格表达式中调用它:

=Code.MinsToHHMM(Avg(Fields!test.Duration.Value))

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

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