Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MatheusRuiz
Frequent Visitor

How to get the latest record for each Key?

Hello, everyone. Hope someone can help me on that.

 

This is my example table:

MatheusRuiz_1-1663867820082.png

 

I want to create a table visualization that shows only the last record for each Vehicle, and only if in this last record the value in the Type column is "ARRIVING".

 

I created this desired table in excel manually, but I need it automated in Power BI due to the large database. 

This is the view I need for the above example:

MatheusRuiz_3-1663868503839.png

Note that I have 7 different vehicles in the original table and in the visualization I have only 2.

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

@MatheusRuiz ,

Apologies for misunderstanding your original post.
I'm hoping this New Table will work for you:

LastArrivalTable = SUMMARIZE(
                        FILTER( Vehicle,
                                Vehicle[Date]
                                = CALCULATE (MAX ( Vehicle[Date] ),
                                   ALLEXCEPT ( Vehicle, Vehicle[Vehicle] ))),
                    Vehicle[Vehicle],
                    Vehicle[Date],
                    Vehicle[Location],
                    Vehicle[Type] )

This table will give you both ARRIVING and LEAVING.  You can use the Filter Pane to filter out LEAVING.  Pretty sure there should be a way to add this filter into the formula above, I just wasn't able to figure it out before I had to move on to some other work.

Best Regards,

View solution in original post

3 REPLIES 3
rsbin
Super User
Super User

@MatheusRuiz ,

Add your table visual into your canvas.

From your Field List, drag Vehicle and Location into the Values well. 

Drag Date, but select "Latest" from the dropdown.

Then drag Type into the "Filters on this Visual" pane.  Check "ARRIVING".

This should get you what you are after.  If not, please post a small sample of your data as a table (not an image).

Regards,

@rsbin,

 

I did as you said:

- created a table visual.

- dragged Vehicle into the Columns (instead of Values).

- then dragged Location and Date into the Columns. 

- selected Latest Date. But here is the problem: when I select that, the visual shows the latest record for each Vehicle+Location instead of the latest record for each Vehicle. 

 

I could not insert my table here, but see what I am saying:

MatheusRuiz_1-1663934483167.png

Note that I have two rows for the vehicles FHC and UBZ (the data is sorted by Date).

 

I thought that excluding Location from the Columns I would get what I want. But when I do that, the table search for the latest "ARRIVING" record for each vehicle (returning 5 records, and in this example should be only 2 as I presented in the post).

I want the latest record for each vehicle and then I want to check if it is "ARRIVING"...

 

I am thinking that would be necessary to use a programming language, what do you say?

 

Thx!

 

 

@MatheusRuiz ,

Apologies for misunderstanding your original post.
I'm hoping this New Table will work for you:

LastArrivalTable = SUMMARIZE(
                        FILTER( Vehicle,
                                Vehicle[Date]
                                = CALCULATE (MAX ( Vehicle[Date] ),
                                   ALLEXCEPT ( Vehicle, Vehicle[Vehicle] ))),
                    Vehicle[Vehicle],
                    Vehicle[Date],
                    Vehicle[Location],
                    Vehicle[Type] )

This table will give you both ARRIVING and LEAVING.  You can use the Filter Pane to filter out LEAVING.  Pretty sure there should be a way to add this filter into the formula above, I just wasn't able to figure it out before I had to move on to some other work.

Best Regards,

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.