Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Identify the most recent data

Hi,

 

I have a data dump from a vehicle tracking system, that records the time, location etc each time a vehicle's ignition is switched on or off. A simplified view is as below:

 

VehicleStatusTimeLocation
Vehicle ASTART14/07/2020 14:44N26°08.853 E049°53.233
Vehicle ASTOP14/07/2020 13:59N26°08.050 E049°52.450
Vehicle ASTART14/07/2020 13:29N26°14.482 E049°59.775
Vehicle ASTOP14/07/2020 11:59N26°15.993 E050°01.205
Vehicle ASTART14/07/2020 11:43N26°10.472 E049°55.988
Vehicle BSTOP14/07/2020 19:29N24°07.455 E049°06.635
Vehicle BSTART14/07/2020 19:14N24°12.902 E049°05.660
Vehicle BSTOP14/07/2020 18:29N24°42.993 E049°05.212
Vehicle BSTART14/07/2020 17:59N24°43.668 E049°05.543

 

I have then created a second table which just lists the vehicles. How can I populate that table with only the most recent records from the data dump (the blue lines above)?

 

Thanks!

  • Anonymous 

    Add this in your vehicles table:

    Lastest Time = CALCULATE(MAX('Table'[Time]),'Table'[Vehicle]=EARLIER(VEHICLES[Vehicle]))

    ________________________

    Did I answer your question? Mark this post as a solution, this will help others!.

    Click on the Thumbs-Up icon on the right if you like this reply 🙂

    YouTube, LinkedIn

8 Replies

  • Anonymous 

    Add this in your vehicles table:

    Lastest Time = CALCULATE(MAX('Table'[Time]),'Table'[Vehicle]=EARLIER(VEHICLES[Vehicle]))

    ________________________

    Did I answer your question? Mark this post as a solution, this will help others!.

    Click on the Thumbs-Up icon on the right if you like this reply 🙂

    YouTube, LinkedIn
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you! Thought it was an easy thing, I was just missing EARLIER.

    • parry2k's avatar
      parry2k
      Super User

      Anonymous add a measure using following expression:

       

      Recent Date = 
      CALCULATE ( MAX ( Table[Date] ), ALLEXCEPT ( Table, Table[Vehicle] ) ) 

       

      I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

      Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sorry, thought that was all I needed - how can I edit that to pull through the other columns (status, location etc)?

      • Fowmy's avatar
        Fowmy
        Super User

        Anonymous 

        If you need a new table that brings only the records for each vehicle with its latest date, add this code by clicking on the New Table under Home tab:

        Latest Dates Table= 
        FILTER(
            'Table',
            VAR _MAX = 
                CALCULATE(
                    MAX('Table'[Time]),
                    ALLEXCEPT('Table',VEHICLES[Vehicle])
                )
            RETURN
            'Table'[Time] = _MAX
        )

         

        ________________________

        Did I answer your question? Mark this post as a solution, this will help others!.

        Click on the Thumbs-Up icon on the right if you like this reply 🙂

        YouTube, LinkedIn

         

  • richbenmintz's avatar
    richbenmintz
    Resident Rockstar

    Hi Anonymous,

     

    Wow parry2k and Fowmy  are fast, 

     

    Another approach would be to derive the rows you are looking for during data ingestion. see the linked .pbix.

    essentially ranks the data in power query then creates a filtered table  where the rank = 1

     

    sample.pbix 

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      I like the look of your solution, saves the need for the second table, but I'm not sure how you got to the stage in your screenshot? I have very limited knowledge of the query editor 😕