Forum Discussion
Adjacent row formula using IF statement
- 5 years ago
Hi Alanoudfahad ,
Try the following formula to create measures:
next_in/out = var next_time = MINX( FILTER( ALL('Table'), 'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date]) && 'Table'[Time] > MAX('Table'[Time]) ), 'Table'[Time] ) var next_in_out = CALCULATE( MAX('Table'[In/out]), FILTER( ALL('Table'), 'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date]) && 'Table'[Time] = next_time ) ) return next_in_outDiff_time = var next_time = MINX( FILTER( ALL('Table'), 'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date]) && 'Table'[Time] > MAX('Table'[Time]) ), 'Table'[Time] ) return next_time - MAX('Table'[Time])TotalTime = IF( MAX('Table'[In/out]) = "IN" && [next_in/out] = "OUT", [Diff_time] )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
WinnizIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Alanoudfahad ,
Try the following formula to create measures:
next_in/out =
var next_time =
MINX(
FILTER(
ALL('Table'),
'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date])
&& 'Table'[Time] > MAX('Table'[Time])
),
'Table'[Time]
)
var next_in_out =
CALCULATE(
MAX('Table'[In/out]),
FILTER(
ALL('Table'),
'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date])
&& 'Table'[Time] = next_time
)
)
return next_in_outDiff_time =
var next_time =
MINX(
FILTER(
ALL('Table'),
'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date])
&& 'Table'[Time] > MAX('Table'[Time])
),
'Table'[Time]
)
return next_time - MAX('Table'[Time])TotalTime =
IF(
MAX('Table'[In/out]) = "IN" && [next_in/out] = "OUT",
[Diff_time]
)
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Alanoudfahad5 years agoFrequent Visitor
Hi v-kkf-msft Thank you so much for the reply! I think we are almost there however, it's only showing my the IN and not the OUT, any idea?
- v-kkf-msft5 years agoCommunity Support
Hi Alanoudfahad ,
If you want to show total value, modify the measure:
TotalTime = var result = IF( MAX('Table'[In/out]) = "IN" && [next_in/out] = "OUT", [Diff_time], 0 ) return IF( ISFILTERED('Table'[Time]), FORMAT(result,"hh:nn:ss"), FORMAT( SUMX(FILTER(ALL('Table'), 'Table'[In/out] = "IN" && [next_in/out] = "OUT"), [Diff_time] ), "hh:nn:ss" ) ) - v-kkf-msft5 years agoCommunity Support
Hi Alanoudfahad ,
Do you want show the OUT as 0:00:00 as shown before? If so, modify measure TotalTime to the following formula:
TotalTime = var result = IF( MAX('Table'[In/out]) = "IN" && [next_in/out] = "OUT", [Diff_time], 0 ) return FORMAT(result,"hh:nn:ss")If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
WinnizIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.