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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
KG1
Resolver I
Resolver I

Last record based on latest date - Power Query

Hi 

I need to find the latest entry using the lastest date against each record. I need to do this in Power Query

 

My table looks like this

KG1_4-1657181132895.png

 

 

I have used the group by method to find the lastest date by Person Number

 

KG1_5-1657181167770.png

 

 

but when I expand the table it brings back all records

 

KG1_6-1657181186102.png

 

#"Grouped Rows" = Table.Group(#"Filtered Rows4", {"Person Number"}, {{"Count", each List.Max([Date created]), type datetime}, {"Table", each _, type table [Date created=datetime, Person Number=text, Ethnicity=text]}}),
#"Expanded Table" = Table.ExpandTableColumn(#"Grouped Rows", "Table", {"Ethnicity"}, {"Ethnicity"})
in
#"Expanded Table"

 

What do I need to do to only have the latest record?

I need it to look like this

KG1_8-1657181260209.png

 

 

Thank you in advance

 

 

 

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @KG1 ,

I have created a sample pbix file, you can find the attachment for the details.  You can update the codes in your Advanced Editor as below:

1. Expanded table also include the column "Date created"

2. Filter the rows which the value of the column [Date created] is equal to max([Date created])

#"Grouped Rows" = Table.Group(#"Filtered Rows4", {"Person Number"}, {{"Count", each List.Max([Date created]), type nullable datetime}, {"Table", each _, type table [Date created=nullable datetime, Person Number=nullable text, Ethnicity=nullable text]}}),
#"Expanded Table" = Table.ExpandTableColumn(#"Grouped Rows", "Table", {"Date created", "Ethnicity"}, {"Date created", "Ethnicity"}),
#"Filter Rows" = Table.SelectRows( #"Expanded Table", each([Count]=[Date created]))
in
#"Filter Rows"

yingyinr_0-1657702541463.png

In addition, you can refer the following links to get it.

load latest date record

How to filter a table to show only most recent date by group in Power Query

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @KG1 ,

I have created a sample pbix file, you can find the attachment for the details.  You can update the codes in your Advanced Editor as below:

1. Expanded table also include the column "Date created"

2. Filter the rows which the value of the column [Date created] is equal to max([Date created])

#"Grouped Rows" = Table.Group(#"Filtered Rows4", {"Person Number"}, {{"Count", each List.Max([Date created]), type nullable datetime}, {"Table", each _, type table [Date created=nullable datetime, Person Number=nullable text, Ethnicity=nullable text]}}),
#"Expanded Table" = Table.ExpandTableColumn(#"Grouped Rows", "Table", {"Date created", "Ethnicity"}, {"Date created", "Ethnicity"}),
#"Filter Rows" = Table.SelectRows( #"Expanded Table", each([Count]=[Date created]))
in
#"Filter Rows"

yingyinr_0-1657702541463.png

In addition, you can refer the following links to get it.

load latest date record

How to filter a table to show only most recent date by group in Power Query

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I used the video link you shared and it works! Thanks!

 

https://www.youtube.com/watch?v=hidJ5T_DYQ0

amitchandak
Super User
Super User

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.