Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!View all the Fabric Data Days sessions on demand. View schedule
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 November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 18 | |
| 11 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 31 | |
| 25 | |
| 21 | |
| 14 | |
| 12 |