Forum Discussion
Anonymous
5 years agoNot applicable
Substract from Different Rows on a Table
Hi Team. Is there a way to reproduce this in Powerbi.? This is the table I have to, in theory, I would like to subtract the time or duration between 1:11 AM and 1:04AM the same way I did in my...
v-alq-msft
5 years agoCommunity Support
Hi, Anonymous
Based on your descripton, I created data to reproduce your sceanrio. The pbix file is attached in the end.
Table:
You may create an index column in Power Query and then create a measure or a column as below.
Measure:
Result Measure =
var totalseconds =
DATEDIFF(
CALCULATE(
MAX('Table'[Status End Datetime]),
FILTER(
ALL('Table'),
[Index]=MAX('Table'[Index])-1
)
),MAX('Table'[Status Start Datetime]),SECOND
)
var m =
COALESCE(INT(DIVIDE(totalseconds,60)),0)
var s = COALESCE(MOD(totalseconds,60),0)
return
m&":"&s
Calculated column:
Result Column =
var totalseconds =
DATEDIFF(
CALCULATE(
MAX('Table'[Status End Datetime]),
FILTER(
ALL('Table'),
[Index]=EARLIER('Table'[Index])-1
)
),[Status Start Datetime],SECOND
)
var m =
COALESCE(INT(DIVIDE(totalseconds,60)),0)
var s = COALESCE(MOD(totalseconds,60),0)
return
m&":"&s
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.