cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Welsh_Will
Helper II
Helper II

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!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Welsh_Will 

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
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

8 REPLIES 8
richbenmintz
Super User
Super User

Hi @Welsh_Will,

 

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 

 

richbenmintz_0-1596033243206.png

 



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


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 😕

Fowmy
Super User
Super User

@Welsh_Will 

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
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

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

@Welsh_Will 

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

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you! I think this is exactly what we need 👍

@Welsh_Will 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.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





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

Helpful resources

Announcements
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors