Forum Discussion
Time Difference between consecutive rows
- 5 years ago
Hi, ziyabikram96
To create a calculated column like this:
isIN_is0 = VAR _previouIn = CALCULATE ( MIN ( [Index] ), FILTER ( ALL ( 'Table' ), [State] = "C/In" && [Index] = EARLIER ( [Index] ) - 1 ) ) VAR _if = IF ( 'Table'[State] = "C/In", IF ( [Index] - _previouIn = 1, 1 ) ) RETURN _ifthen the test3 would be like this:
test_3 = VAR _CurrentIndex = FIRSTNONBLANK ('Table'[Index], 1 ) VAR _CurrentStatus = FIRSTNONBLANK ( 'Table'[State], 1 ) VAR _IndexOfPreviousCheckIN = CALCULATE ( MAX ( 'Table'[Index] ), FILTER ( ALL ( 'Table' ), AND ( 'Table'[Index] < _CurrentIndex, 'Table'[State] = "C/In" ) ) //,OR('InOutData(PAK)'[Index] < CurrentIndex, // 'InOutData(PAK)'[State] = "C/Out") ) //***************************************************************************************** var _lastOut= CALCULATE( LASTNONBLANK('Table'[Index],MAX('Table'[State])="C/Out"), FILTER(ALL('Table'),AND ( 'Table'[Index] < _CurrentIndex, 'Table'[State] = "C/Out" )) ) //***************************************************************************************** //***************************************************************************************** var _firstIn= IF(MAX('Table'[State])="C/In",_lastOut+1) //***************************************************************************************** VAR _IndexOfFollowingCheckOut = IF ( ISBLANK ( _IndexOfPreviousCheckIN ), 0, // _IndexOfPreviousCheckIN+1 //***************************************************************************************** _lastOut //***************************************************************************************** ) var _result= IF ( OR( //***************************************************************************************** OR ( _CurrentIndex = 0, _CurrentStatus = "C/Out" ),MAX('Table'[isIN_is0])=1), //***************************************************************************************** 0, DATEDIFF ( CALCULATE ( FIRSTNONBLANK ( 'Table'[Date & Time State], 0 ), FILTER ( ALL ( 'Table' ), 'Table'[Index] = _IndexOfFollowingCheckOut ) ), // FIRSTNONBLANK ( 'Table'[Date & Time State], 1 ), //***************************************************************************************** CALCULATE( MAX('Table'[Date & Time State]), FILTER( ALL('Table'), 'Table'[Index]=_firstIn ) ), //***************************************************************************************** MINUTE ) ) RETURN _resultresult:
Please refer to the attachment below for details
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, ziyabikram96
I have made some modifications to the above formula:
test2 =
VAR _CurrentIndex =
FIRSTNONBLANK ('Table'[Index], 1 )
VAR _CurrentStatus =
FIRSTNONBLANK ( 'Table'[State], 1 )
VAR _IndexOfPreviousCheckIN =
CALCULATE (
MAX ( 'Table'[Index] ),
FILTER (
ALL ( 'Table' ),
AND ( 'Table'[Index] < _CurrentIndex, 'Table'[State] = "C/In" )
) //,OR('InOutData(PAK)'[Index] < CurrentIndex,
// 'InOutData(PAK)'[State] = "C/Out")
)
//*****************************************************************************************
var _lastOut=
CALCULATE(
LASTNONBLANK('Table'[Index],MAX('Table'[State])="C/Out"),
FILTER(ALL('Table'),AND ( 'Table'[Index] < _CurrentIndex, 'Table'[State] = "C/Out" ))
)
//*****************************************************************************************
VAR _IndexOfFollowingCheckOut =
IF (
ISBLANK ( _IndexOfPreviousCheckIN ),
0,
// _IndexOfPreviousCheckIN+1
//*****************************************************************************************
_lastOut
//*****************************************************************************************
)
var _result=
IF (
OR ( _CurrentIndex = 0, _CurrentStatus = "C/Out" ),
0,
DATEDIFF (
CALCULATE (
FIRSTNONBLANK ( 'Table'[Date & Time State], 0 ),
FILTER (
ALL ( 'Table' ),
'Table'[Index] = _IndexOfFollowingCheckOut
)
),
FIRSTNONBLANK ( 'Table'[Date & Time State], 1 ),
MINUTE
)
)
RETURN _result
Result:
Please refer to the attachment below for details
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ziyabikram965 years agoHelper V
Thanks for your time and response in C/Out logic is ok as it is highlited in yellow but the problem is occured in C/In as it is marked with black colour , I want minimum C/In and thier respective result and rest of it will return 0
- ziyabikram965 years agoHelper V
and for more clarification i want difference between
last_Out and First_In
- v-angzheng-msft5 years agoCommunity Support
Hi, ziyabikram96
To create a calculated column like this:
isIN_is0 = VAR _previouIn = CALCULATE ( MIN ( [Index] ), FILTER ( ALL ( 'Table' ), [State] = "C/In" && [Index] = EARLIER ( [Index] ) - 1 ) ) VAR _if = IF ( 'Table'[State] = "C/In", IF ( [Index] - _previouIn = 1, 1 ) ) RETURN _ifthen the test3 would be like this:
test_3 = VAR _CurrentIndex = FIRSTNONBLANK ('Table'[Index], 1 ) VAR _CurrentStatus = FIRSTNONBLANK ( 'Table'[State], 1 ) VAR _IndexOfPreviousCheckIN = CALCULATE ( MAX ( 'Table'[Index] ), FILTER ( ALL ( 'Table' ), AND ( 'Table'[Index] < _CurrentIndex, 'Table'[State] = "C/In" ) ) //,OR('InOutData(PAK)'[Index] < CurrentIndex, // 'InOutData(PAK)'[State] = "C/Out") ) //***************************************************************************************** var _lastOut= CALCULATE( LASTNONBLANK('Table'[Index],MAX('Table'[State])="C/Out"), FILTER(ALL('Table'),AND ( 'Table'[Index] < _CurrentIndex, 'Table'[State] = "C/Out" )) ) //***************************************************************************************** //***************************************************************************************** var _firstIn= IF(MAX('Table'[State])="C/In",_lastOut+1) //***************************************************************************************** VAR _IndexOfFollowingCheckOut = IF ( ISBLANK ( _IndexOfPreviousCheckIN ), 0, // _IndexOfPreviousCheckIN+1 //***************************************************************************************** _lastOut //***************************************************************************************** ) var _result= IF ( OR( //***************************************************************************************** OR ( _CurrentIndex = 0, _CurrentStatus = "C/Out" ),MAX('Table'[isIN_is0])=1), //***************************************************************************************** 0, DATEDIFF ( CALCULATE ( FIRSTNONBLANK ( 'Table'[Date & Time State], 0 ), FILTER ( ALL ( 'Table' ), 'Table'[Index] = _IndexOfFollowingCheckOut ) ), // FIRSTNONBLANK ( 'Table'[Date & Time State], 1 ), //***************************************************************************************** CALCULATE( MAX('Table'[Date & Time State]), FILTER( ALL('Table'), 'Table'[Index]=_firstIn ) ), //***************************************************************************************** MINUTE ) ) RETURN _resultresult:
Please refer to the attachment below for details
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- ziyabikram965 years agoHelper V
Thanks for your time and kind responses I got my expected result