Forum Discussion

RichardT_78's avatar
RichardT_78
Icon for Helper I rankHelper I
3 years ago
Solved

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 
1001111014/03/2011 13:30In Hours 
153261214/03/2011 03:37In Hours 
100111167814/03/2011 13:31In Hours 
201521214/03/2011 03:31In Hours 
2015211714/03/2011 12:38In Hours 
153261214/03/2011 03:37In Hours 
1001111214/03/2011 09:30In Hours 
153261167813/03/2011 11:31In Hours 
2015261214/03/2011 11:31In Hours 
153261214/03/2011 06:37In Hours 
201521167814/03/2011 06:30In 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

  • 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's avatar
      RichardT_78
      Icon for Helper I rankHelper 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.