time - Power BI Avg 加权时间格式度量
问题描述
我创建了两个度量来计算我的加权 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测量时,它会抛出结果。有没有一种方法可以操纵以时间格式显示但结果正确。
以下是非时间格式的正确结果。
这是我要绑定的屏幕截图。
inboundlog 表中数据类型的屏幕截图。
解决方案
使用此处的代码: 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,
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 ) ) )
)
推荐阅读
- terraform - Terraform:在调用应用或销毁时停止打印计划到控制台
- sql-server - bcp 右截断错误,但以前使用 bcp 创建的表格式,除非我使用 -c
- ios - 对于视图模型中的快速引用,自引用应该是弱的还是未知的?
- nestjs - NotNullConstraintViolationException on npx mikro-orm migration:up
- python - 我无法在 Python 中显示这两个小部件
- python - 如何获得将非线性可分数据投影为线性可分的正确径向基函数?
- apache - 使用 mod_rewrite 在不同的、非连续的文件夹中搜索文件或目录
- ios - 在“__strong id”类型的对象上找不到属性“桥”
- https - 读取 X.509 密钥或证书文件时出错
- reactjs - 状态挂钩不会在 redux 存储更新时更新状态参数