Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hello.
I'm trying to do a time duration here based on a lookup.
I want to find duration that Column A > x to value Column A NOT > x.
For example:
Column A > x at 12/12/21 09:00.
Column A became NOT > x at 12/12/21 09:43
Duration would be the difference. I know this is a dumb question but I assume the lookup or Select moves forward in time? Never backwards?
I would expect a result of list of duration values.
Thanks for any help.
Solved! Go to Solution.
Hi, @hxnwx ,
You could create a measure as follow:
Measure =
var _next=CALCULATE(MAX('Table'[DATE/TIME]),FILTER(ALL('Table'),[A]=MAX([A])&&[Status]="No"))
var _dura= DATEDIFF(MAX('Table'[DATE/TIME]), _next,SECOND)
return RIGHT ( "0" & INT ( _dura / 3600 ), 2 )
& ":"
& RIGHT (
"0"
& INT ( ( _dura - INT (_dura / 3600 ) * 3600 ) / 60 ),
2
)
& ":"
& RIGHT ( "0" & MOD (_dura, 60 ), 2 )
The final show:
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @hxnwx
Try it.
Measure =
var _pre=CALCULATE(MIN('Table'[DATE/TIME]),FILTER(ALL('Table'),[DATE/TIME]<MAX('Table'[DATE/TIME])&&[lo_ifr_ind]=1))
var _dur= DATEDIFF(_pre,MAX('Table'[DATE/TIME]),SECOND)
var _dura=IF(MAX('Table'[lo_ifr_ind])= CALCULATE(MAX('Table'[lo_ifr_ind]),FILTER(ALL('Table'),[DATE/TIME]= CALCULATE(MAX('Table'[DATE/TIME]),FILTER(ALL('Table'),[DATE/TIME]<MAX('Table'[DATE/TIME]))))),"00:00:00",_dur)
return
RIGHT ( "0" & INT ( _dura / 3600 ), 2 )
& ":"
& RIGHT (
"0"
& INT ( ( _dura - INT (_dura / 3600 ) * 3600 ) / 60 ),
2
)
& ":"
& RIGHT ( "0" & MOD (_dura, 60 ), 2 )
The final show:
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @hxnwx
Try it.
Measure =
var _pre=CALCULATE(MIN('Table'[DATE/TIME]),FILTER(ALL('Table'),[DATE/TIME]<MAX('Table'[DATE/TIME])&&[lo_ifr_ind]=1))
var _dur= DATEDIFF(_pre,MAX('Table'[DATE/TIME]),SECOND)
var _dura=IF(MAX('Table'[lo_ifr_ind])= CALCULATE(MAX('Table'[lo_ifr_ind]),FILTER(ALL('Table'),[DATE/TIME]= CALCULATE(MAX('Table'[DATE/TIME]),FILTER(ALL('Table'),[DATE/TIME]<MAX('Table'[DATE/TIME]))))),"00:00:00",_dur)
return
RIGHT ( "0" & INT ( _dura / 3600 ), 2 )
& ":"
& RIGHT (
"0"
& INT ( ( _dura - INT (_dura / 3600 ) * 3600 ) / 60 ),
2
)
& ":"
& RIGHT ( "0" & MOD (_dura, 60 ), 2 )
The final show:
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Yalan Wu,
I think this is close though I might have the column names incorrect in Measure.
I get the following response. I can see the Duration column(Measure).
I would expect to see a value in this column on the 6/5/2022 1:42:00 PM row.
This is where column 'lo_ifr_ind' changed from 1 to 0. The duration it was = 1, should be from:
6/5/2022 10:39:00 AM (changed from 0 to 1)
6/5/2022 1:42:00 PM (changed from 1 back to 0)
So duration would be close to 03:03:00.
Here is what I have for the Measure:
Duration = var _next=CALCULATE(MAX('Query1'[wthr_prd_iss_gts]),FILTER(ALL('Query1'),[wthr_prd_iss_gts]=MAX([wthr_prd_iss_gts])&&[lo_ifr_ind]=0)) var _dura= DATEDIFF(MAX('Query1'[wthr_prd_iss_gts]), _next,SECOND) return RIGHT ( "0" & INT ( _dura / 3600 ), 2 ) & ":" & RIGHT ( "0" & INT ( ( _dura - INT (_dura / 3600 ) * 3600 ) / 60 ), 2 ) & ":" & RIGHT ( "0" & MOD (_dura, 60 ), 2 )
Hi, @hxnwx ,
You could create a measure as follow:
Measure =
var _next=CALCULATE(MAX('Table'[DATE/TIME]),FILTER(ALL('Table'),[A]=MAX([A])&&[Status]="No"))
var _dura= DATEDIFF(MAX('Table'[DATE/TIME]), _next,SECOND)
return RIGHT ( "0" & INT ( _dura / 3600 ), 2 )
& ":"
& RIGHT (
"0"
& INT ( ( _dura - INT (_dura / 3600 ) * 3600 ) / 60 ),
2
)
& ":"
& RIGHT ( "0" & MOD (_dura, 60 ), 2 )
The final show:
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks Yalan.