问题描述
我创建了两个度量来计算我的加权 ACW 平均值,但时间格式显示不正确,我被卡住了。我有一个从 Postgres 导入 Powerbi 的表,我用于 acw 时间的列在 Inboundlog 表中以秒为单位。
为了得到我的平均值,我首先创建了一个度量来总结 ACW 的总时间。
SUM ACW = SUM(inboundlog[time_acwork])
AVG ACW = DIVIDE([SUM ACW],[Calls Handled])
添加到我的表格后,它显示了正确的结果,但不是按时间格式显示的。当我将格式添加到“HH:MM:SS”或“MM:SS”的 AVG ACW meausre 时,它会抛出结果。有没有办法可以操作以时间格式显示但具有正确的结果。
以下是非时间格式的正确结果。
这是我要绑定的屏幕截图。
入站日志表中数据类型的屏幕截图。
解决方法
使用此处的代码: https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486
Duration =
// 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 = [Duration in Seconds]
// 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,Minutes ),Minutes )
)
// Seconds with leading zeros
VAR S =
IF (
LEN ( Seconds ) = 1,Seconds ),Seconds )
)
// Now return hours,minutes and seconds with leading zeros in the proper format "hh:mm:ss"
RETURN
CONCATENATE (
H,CONCATENATE ( ":",CONCATENATE ( M,S ) ) )
)