Forum Discussion
Anonymous
8 years agoNot applicable
Help with Measure
Hi, I need help from you guys for calculating the difference between two time stamps , below is as example of the exact output that I need. Appreciate your help ! ID Time Received Action ...
- 8 years ago
Hi Anonymous,
glad it worked out for you. For formatting the result, you may find these additional measures useful:
DiffMinutes = QUOTIENT([Diff], 60) DiffSeconds = [Diff] - [DiffMinutes] * 60 DiffMinSec = [DiffMinutes] & "." & FORMAT([DiffSeconds],"00")
If all you need is the [DiffMinSec] you can fold it together as:
DiffMinSec = QUOTIENT([Diff], 60) & "." & FORMAT([Diff] - QUOTIENT([Diff], 60) * 60,"00")
Zubair_Muhammad
8 years agoCommunity Champion
Hi Anonymous
Add this calculated Column
=
VAR Previoustime =
MAXX (
FILTER ( Table1, Table1[Time Received] < EARLIER ( Table1[Time Received] ) ),
Table1[Time Received]
)
RETURN
IF (
Table1[Action] = "Out",
DATEDIFF ( Previoustime, Table1[Time Received], MINUTE )
)erik_tarnvik
8 years agoSolution Specialist
Good solution from Zubair_Muhammad. You may want to check the Action in the filter condition in case times can overlap. Like this:
=
VAR Previoustime =
MAXX (
FILTER ( Table1, Table1[Time Received] < EARLIER ( Table1[Time Received] ) &&
Table1[Action] = "In"),
Table1[Time Received]
)
RETURN
IF (
Table1[Action] = "Out",
DATEDIFF ( Previoustime, Table1[Time Received], MINUTE )
)You can also define the same as a measure. It would need to be executed in a filter context where Table1[Time Received] has only one value. It would go something like this:
Diff = DATEDIFF(Calculate(MAX(Table1[Time Received]),
FILTER(ALL(Table1),
Table1[Action] = "In" &&
Table1[Time Received] <= MAX('Time'[Time Received]))),
MAX('Time'[Time Received]),
MINUTE)