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.
Alanoudfahad , Try a new column like this
if( [In/OUT] = "OUT" , datediff(maxx(filter(Table, [In/OUT] = "IN" && [Datetime] < earlier([[Datetime]])),[Datetime]),[Datetime], hour), blank())
and then you can sum this up in measure
Hello amitchandak
It gives me the following error:
Too many arguments were passed to the EARLIER function. The maximum argument count for the function is 2.
Any idea?
- amitchandak5 years agoSuper User
Alanoudfahad , There is small correction in formula,
Create a new column first
if( [In/OUT] = "OUT" , datediff(maxx(filter(Table, [In/OUT] = "IN" && [Datetime] < earlier([Datetime])),[Datetime]),[Datetime], hour), blank())
Then create a new measure with it.