Forum Discussion
power bi time difference
Hi drad2211
az38's measure works.
Time Diff =
VAR LastTimeIn =
CALCULATE (
MAX ( Table1[Time] ),
FILTER (
ALL ( Table1 ),
Table1[Action] = "In"
&& Table1[ID] = SELECTEDVALUE ( Table1[ID] )
&& Table1[Time] < SELECTEDVALUE ( 'Table1'[Time] )
)
)
RETURN
IF (
SELECTEDVALUE ( Table1[Action] ) = "Out",
DATEDIFF ( LastTimeIn, SELECTEDVALUE ( Table1[Time] ), MINUTE ),
""
)
Since Measure doesn't stored in the data model and it can't be used as a item in a slicer,
if you want to create a calculated column, you could create a column like this:
Column =
VAR last_ =
CALCULATE (
MAX ( Table1[Time] ),
FILTER (
Table1,
Table1[ID] = EARLIER ( Table1[ID] )
&& Table1[Action] = "In"
&& Table1[Time] < EARLIER ( Table1[Time] )
)
)
RETURN
IF ( [Action] = "Out", DATEDIFF ( last_, [Time], MINUTE ) )
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you, that worked great! One last question, is there a way to state that if the 'Out' isn't preceeded by a 'In' to skip to the next one for flag it with a X or something? Kind of similar to this:
ID Time Action Time Diff
1 12:23:18 05/05/2015 In
2 12:26:26 05/05/2015 In
1 14:23:18 05/05/2015 Out 120
1 15:15:18 05/05/2015 Out (Either leave blank or show as "X")
1 15:23:18 05/05/2015 In
1 16:23:18 05/05/2015 Out 60
2 16:26:26 05/05/2015 Out 240
. . .
. . .