Forum Discussion
Time spent in programm - measure
- Anonymous1 year ago
Hi Fistachpl
First, create a calculated column for session end time:EndTime = VAR CurrentUser = TProgram[User] VAR CurrentDateTime = TProgram[dateandtime] VAR CurrentDate = DATE(YEAR(CurrentDateTime), MONTH(CurrentDateTime), DAY(CurrentDateTime)) VAR NextLogout = CALCULATE( MIN(TProgram[dateandtime]), FILTER( ALL(TProgram), TProgram[User] = CurrentUser && TProgram[type] = "Logout" && TProgram[dateandtime] > CurrentDateTime && DATE(YEAR(TProgram[dateandtime]), MONTH(TProgram[dateandtime]), DAY(TProgram[dateandtime])) = CurrentDate ) ) VAR NextLogin = CALCULATE( MIN(TProgram[dateandtime]), FILTER( ALL(TProgram), TProgram[User] = CurrentUser && TProgram[type] = "Login" && TProgram[dateandtime] > CurrentDateTime && DATE(YEAR(TProgram[dateandtime]), MONTH(TProgram[dateandtime]), DAY(TProgram[dateandtime])) = CurrentDate ) ) VAR LastEventOfDay = CALCULATE( MAX(TProgram[dateandtime]), FILTER( ALL(TProgram), TProgram[User] = CurrentUser && DATE(YEAR(TProgram[dateandtime]), MONTH(TProgram[dateandtime]), DAY(TProgram[dateandtime])) = CurrentDate ) ) VAR MinNextEvent = SWITCH( TRUE(), NOT ISBLANK(NextLogout) && NOT ISBLANK(NextLogin), MIN(NextLogout, NextLogin), NOT ISBLANK(NextLogout), NextLogout, NOT ISBLANK(NextLogin), NextLogin, BLANK() ) RETURN IF( TProgram[type] = "Login", IF( NOT ISBLANK(MinNextEvent), MinNextEvent, LastEventOfDay ), BLANK() )Then create a calculated column for session duration:
Duration (Hours) = IF( TProgram[type] = "Login", DATEDIFF(TProgram[dateandtime], TProgram[EndTime], SECOND) / 3600, BLANK() )Then create a calculated column to sum the duration:
Total Time Spent (Hours) = SUMX( FILTER(TProgram, TProgram[type] = "Login"), TProgram[Duration (Hours)] )Result:
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Fistachpl
First, create a calculated column for session end time:
EndTime =
VAR CurrentUser = TProgram[User]
VAR CurrentDateTime = TProgram[dateandtime]
VAR CurrentDate = DATE(YEAR(CurrentDateTime), MONTH(CurrentDateTime), DAY(CurrentDateTime))
VAR NextLogout =
CALCULATE(
MIN(TProgram[dateandtime]),
FILTER(
ALL(TProgram),
TProgram[User] = CurrentUser &&
TProgram[type] = "Logout" &&
TProgram[dateandtime] > CurrentDateTime &&
DATE(YEAR(TProgram[dateandtime]), MONTH(TProgram[dateandtime]), DAY(TProgram[dateandtime])) = CurrentDate
)
)
VAR NextLogin =
CALCULATE(
MIN(TProgram[dateandtime]),
FILTER(
ALL(TProgram),
TProgram[User] = CurrentUser &&
TProgram[type] = "Login" &&
TProgram[dateandtime] > CurrentDateTime &&
DATE(YEAR(TProgram[dateandtime]), MONTH(TProgram[dateandtime]), DAY(TProgram[dateandtime])) = CurrentDate
)
)
VAR LastEventOfDay =
CALCULATE(
MAX(TProgram[dateandtime]),
FILTER(
ALL(TProgram),
TProgram[User] = CurrentUser &&
DATE(YEAR(TProgram[dateandtime]), MONTH(TProgram[dateandtime]), DAY(TProgram[dateandtime])) = CurrentDate
)
)
VAR MinNextEvent =
SWITCH(
TRUE(),
NOT ISBLANK(NextLogout) && NOT ISBLANK(NextLogin), MIN(NextLogout, NextLogin),
NOT ISBLANK(NextLogout), NextLogout,
NOT ISBLANK(NextLogin), NextLogin,
BLANK()
)
RETURN
IF(
TProgram[type] = "Login",
IF(
NOT ISBLANK(MinNextEvent),
MinNextEvent,
LastEventOfDay
),
BLANK()
)
Then create a calculated column for session duration:
Duration (Hours) =
IF(
TProgram[type] = "Login",
DATEDIFF(TProgram[dateandtime], TProgram[EndTime], SECOND) / 3600,
BLANK()
)
Then create a calculated column to sum the duration:
Total Time Spent (Hours) =
SUMX(
FILTER(TProgram, TProgram[type] = "Login"),
TProgram[Duration (Hours)]
)
Result:
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Fistachpl1 year ago
Helper III
Works like a charm.
If I can have question. Why did You add columns? Is it not possible to do this via measure?