Forum Discussion
SQL DATEDIFF with lookup
- 4 years ago
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. - 4 years ago
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 ,
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.