如何使Power BI显示时间数据类型列的总和?
场景:包含列Phase(文本)和Duration(SQL Server时间数据类型,也在Power BI中识别,如时间)的表。当我添加条形图,其中相位为轴,持续时间为值时,我只有选项显示持续时间的计数和计数不同,没有SUM。
添加DurationMeasure后的其他说明:
这是DurationMeasure定义(如Karl Anka给出的链接):
DurationMeasure =
// Duration formatting
// * @konstatinos 1/25/2016
// * Given a number of seconds, returns a format of "hh:mm:ss"
//
// We start with a duration in number of seconds
VAR Duration = SUM(TBL1[DurationSeconds])
// There are 3,600 seconds in an hour
VAR Hours =
INT ( Duration / 3600)
// There are 60 seconds in a minute
VAR Minutes =
INT ( MOD( Duration - ( Hours * 3600 );3600 ) / 60)
// Remaining seconds are the remainder of the seconds divided by 60 after subtracting out the hours
VAR Seconds =
ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 );3600 ); 60 );0) // We round up here to get a whole number
// These intermediate variables ensure that we have leading zero's concatenated onto single digits
// Hours with leading zeros
VAR H =
IF ( LEN ( Hours ) = 1;
CONCATENATE ( "0"; Hours );
CONCATENATE ( ""; Hours )
)
// Minutes with leading zeros
VAR M =
IF (
LEN ( Minutes ) = 1;
CONCATENATE ( "0"; Minutes );
CONCATENATE ( ""; Minutes )
)
// Seconds with leading zeros
VAR S =
IF (
LEN ( Seconds ) = 1;
CONCATENATE ( "0"; Seconds );
CONCATENATE ( ""; Seconds )
)
// Now return hours, minutes and seconds with leading zeros in the proper format "hh:mm:ss"
RETURN
CONCATENATE (
H;
CONCATENATE ( ":"; CONCATENATE ( M; CONCATENATE ( ":"; S ) ) )
)
提前致谢
答案 0 :(得分:1)
如果将持续时间转换为十进制数,则可以显示总和。然后是值1 = 1 day = 24 hour = 1440 minutes = 86400 seconds
。所以0.5的值意味着12小时。在图表中将其显示为小时和分钟是一件麻烦事,但是来自Power BI论坛的this显示了它是如何完成的。