Forum Discussion
Time stamps
I am trying to look at a specific event in order to use the date and time stamp to use the datediff function but i cant filter or issolate the timestap that i need to make the function work correctly.
Example
| Car | fault | Time stamp | Time since Event |
| 100111 | 10 | 14/03/2011 13:30 | In Hours |
| 153261 | 2 | 14/03/2011 03:37 | In Hours |
| 100111 | 1678 | 14/03/2011 13:31 | In Hours |
| 201521 | 2 | 14/03/2011 03:31 | In Hours |
| 201521 | 17 | 14/03/2011 12:38 | In Hours |
| 153261 | 2 | 14/03/2011 03:37 | In Hours |
| 100111 | 12 | 14/03/2011 09:30 | In Hours |
| 153261 | 1678 | 13/03/2011 11:31 | In Hours |
| 201526 | 12 | 14/03/2011 11:31 | In Hours |
| 153261 | 2 | 14/03/2011 06:37 | In Hours |
| 201521 | 1678 | 14/03/2011 06:30 | In Hours |
I’m interested in either extracting all 1678 associated dates to use
XXX is the filter
TIME = DATEDIFF(NOW(),[XXX],HOUR)
I need to look at Car and filter fault for 1678 for the latest time/date stamp so i can use the datediff function. But i can’t work out what format the time date stamp should be in to get the latest time/date time stamp?
I’m pretty sure this is commonly asked question but couldn’t find anything other than filtering by time stamps rather than this way round.
Any Help would be much apricated
Hi , RichardT_78
According to your description, you want to get the datediff between the latest timestamp each Car and the Now().
If this , you can refer to these steps .
(1)My test data is the same as yours.
(2)We can create a measure:
Measure = var _cur_car_table = FILTER(ALLSELECTED('Table') ,'Table'[Car ]= MAX('Table'[Car ])&& 'Table'[fault ]=1678) var _t2= ADDCOLUMNS(_cur_car_table,"minus" , ABS([Time stamp ]-NOW())) var _latest = MINX(_t2,[minus]) var _t3 = FILTER(_t2 ,[minus] = _latest) return DATEDIFF(MAXX(_t3,[Time stamp ]),NOW(),HOUR)(3)Then we can meet your need:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
2 Replies
- v-yueyunzh-msft
Community Support
Hi , RichardT_78
According to your description, you want to get the datediff between the latest timestamp each Car and the Now().
If this , you can refer to these steps .
(1)My test data is the same as yours.
(2)We can create a measure:
Measure = var _cur_car_table = FILTER(ALLSELECTED('Table') ,'Table'[Car ]= MAX('Table'[Car ])&& 'Table'[fault ]=1678) var _t2= ADDCOLUMNS(_cur_car_table,"minus" , ABS([Time stamp ]-NOW())) var _latest = MINX(_t2,[minus]) var _t3 = FILTER(_t2 ,[minus] = _latest) return DATEDIFF(MAXX(_t3,[Time stamp ]),NOW(),HOUR)(3)Then we can meet your need:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- RichardT_78
Helper I
Yes this is perfect , thank you very much, ive been scratching my head trying to find a solution. I tried lookup but due to multiple rows it didnt work.