Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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-1 13:00:00 |
1 | Active | 2020-1-1 14:00:00 |
1 | Logout | 2020-1-1 15:03:00 |
2 | .. | .. |
2 | .. | .. |
Solved! Go to Solution.
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] )
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] )
Thanks Jihwan, it works perfect!
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
28 | |
12 | |
10 | |
10 | |
6 |