Forum Discussion
Measure to filter days between operations
- 6 years ago
Hi Tommyvhod ,
Try these two measures to get the result in the picture. My table name is Fin.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
NathanielDate diff = VAR _Time = ( Fin[Finish date] ) //captures current date Var _maxLastTime = CALCULATE(MAX(Fin[Finish date]),FILTER(ALLEXCEPT(Fin,Fin[ID ]),Fin[Finish date]< _Time)) var _datedif =DATEDIFF(_maxLastTime,Fin[Finish date],day) return if(_datedif>0,_datedif,0) ================== Date Dif per ID = CALCULATE(DATEDIFF(MIN(Fin[Finish date]),MAX(Fin[Finish date]),DAY),Filter(ALLEXCEPT(fin,Fin[ID ]),Fin[ID ])
The only issues are the duplicate values for operations on same day. I add another excel example with some operations on same day.
| ID | Operation | Transaction Date | Time |
| 1167900 | 30 | 10. 7. 2019 | 05:51 |
| 1167900 | 35 | 10. 7. 2019 | 05:51 |
| 1167900 | 50 | 10. 7. 2019 | 08:37 |
| 1167900 | 70 | 10. 7. 2019 | 08:38 |
| 1167900 | 80 | 10. 7. 2019 | 08:54 |
| 1167900 | 90 | 10. 7. 2019 | 10:07 |
| 1167900 | 110 | 10. 7. 2019 | 10:19 |
| 1167900 | 190 | 10. 7. 2019 | 21:00 |
| 1167900 | 210 | 11. 7. 2019 | 09:32 |
| 1167900 | 317 | 11. 7. 2019 | 15:10 |
| 1167900 | 320 | 11. 7. 2019 | 17:14 |
| 1167900 | 323 | 12. 7. 2019 | 19:20 |
| 1167900 | 330 | 13. 7. 2019 | 07:41 |
| 1167900 | 333 | 13. 7. 2019 | 12:40 |
| 1167900 | 340 | 13. 7. 2019 | 12:40 |
| 1167900 | 343 | 28. 8. 2019 | 09:53 |
| 1167900 | 350 | 28. 8. 2019 | 09:53 |
| 1167900 | 353 | 14. 10. 2019 | 00:50 |
| 1167900 | 360 | 14. 10. 2019 | 01:58 |
| 1167900 | 363 | 14. 10. 2019 | 09:52 |
| 1167900 | 370 | 14. 10. 2019 | 10:40 |
| 1167900 | 401 | 14. 10. 2019 | 16:40 |
| 1167900 | 402 | 14. 10. 2019 | 17:36 |
| 1167900 | 410 | 14. 10. 2019 | 19:40 |
| 1167920 | 30 | 12. 7. 2019 | 11:49 |
| 1167920 | 35 | 12. 7. 2019 | 11:49 |
| 1167920 | 50 | 12. 7. 2019 | 14:23 |
| 1167920 | 70 | 12. 7. 2019 | 16:27 |
| 1167920 | 80 | 12. 7. 2019 | 17:38 |
| 1167920 | 90 | 15. 7. 2019 | 06:43 |
| 1167920 | 110 | 15. 7. 2019 | 13:10 |
| 1167920 | 190 | 15. 7. 2019 | 17:42 |
| 1167920 | 210 | 15. 7. 2019 | 20:50 |
| 1167920 | 317 | 16. 7. 2019 | 02:03 |
| 1167920 | 320 | 16. 7. 2019 | 08:50 |
| 1167920 | 323 | 18. 7. 2019 | 08:23 |
| 1167920 | 330 | 18. 7. 2019 | 10:23 |
| 1167920 | 333 | 18. 7. 2019 | 16:29 |
| 1167920 | 340 | 22. 7. 2019 | 17:44 |
| 1167920 | 343 | 10. 9. 2019 | 10:34 |
| 1167920 | 350 | 18. 9. 2019 | 08:39 |
| 1167920 | 385 | 19. 9. 2019 | 12:59 |
I have a separate column with times as well. If it helps ( or maybe it would be better for me as well to track the hours between operations )
Hi Tommyvhod ,
Ok thanks for the data. I translated the date, and then combined the date and time. See if this makes sense to you. The underlined shows that about 12 hours translates to .50. Do me a favor and look this over, point out the issues that you see.
Thanks,
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
t
- Nathaniel_C6 years ago
Community Champion
Hi Tommyvhod ,
Here is my pbix DATEDIFF
Go to Power Query, select both columns, select Merge Columns, with space for a delimiter, and then change type of the new column to Date Time.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel - Tommyvhod6 years ago
Helper II
Its seems to be good. Did you change anything in the formula?
- Nathaniel_C6 years ago
Community Champion
Hi Tommyvhod ,
Only what you changed, which was adding the time to the date. Which most likely solved your problem of because now we are not solving for days only. Different granularity.
Thanks, it was fun to work on!
Nathaniel
- Tommyvhod6 years ago
Helper II
Could I ask how did you merged the Time and date column together? I simply added a new column and added the formula Date + Time. I received a format that seems to be ok. but when changed the measure formula, pointing to the combined date, all my datediff numbers switched to 74.