Forum Discussion
finn881988
4 years agoFrequent Visitor
[Solved] How to calculate time difference from one column based on various conditions
Goal: Use dax to calculate average employee online time duration (Logout Timestamp - Login Timestamp) Data: Employee No Status Timestamp 1 Login 2020-1-1 12:00:00 1 Inactive 2020-1-...
- 4 years ago
Hi,
Please check the below picture and the attached pbix file.
It is for creating a measure, and it shows by minute.
Online time duration avg: = VAR _duration = ADDCOLUMNS ( VALUES ( Data[Employee No] ), "@duration", DATEDIFF ( CALCULATE ( MAXX ( FILTER ( Data, Data[Status] = "Login" ), Data[Timestamp] ) ), CALCULATE ( MAXX ( FILTER ( Data, Data[Status] = "Logout" ), Data[Timestamp] ) ), MINUTE ) ) RETURN AVERAGEX ( _duration, [@duration] )
Jihwan_Kim
Super User
4 years agoHi,
Please check the below picture and the attached pbix file.
It is for creating a measure, and it shows by minute.
Online time duration avg: =
VAR _duration =
ADDCOLUMNS (
VALUES ( Data[Employee No] ),
"@duration",
DATEDIFF (
CALCULATE ( MAXX ( FILTER ( Data, Data[Status] = "Login" ), Data[Timestamp] ) ),
CALCULATE ( MAXX ( FILTER ( Data, Data[Status] = "Logout" ), Data[Timestamp] ) ),
MINUTE
)
)
RETURN
AVERAGEX ( _duration, [@duration] )
finn881988
4 years agoFrequent Visitor
Thanks Jihwan, it works perfect!