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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

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
Anonymous
Not applicable

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

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

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

 

Hi @KG1 @Anonymous @amitchandak @danielrios96 

I am trying to get only one record of instance ID based on max of time of exec date.but grouping not working.. Can you please help me out to get unique record based on last time of the date.  

ashish_18_0-1745898240817.png

 

Thanks in advance for your help and support...

 

@ashish_18  I would say is because your grouping is on just your date column so its bringing back duplicate rows - duplicate both your date and time columns, format both columns as text, higlight the duplicated date column first, then the time column, right click, merge and use space as a delimiter, format your new column as date and time then do your max grouping steps addding in the date time fields if you need them

Thanks @KG1 . I will follow this direction for grouping. Really appreciate ur help!!

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

 

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

  • Video https://www.youtube.com/watch?v=hidJ5T_DYQ0was great. Summary -
  • Simply take the groupby for the entire data by the unique ID column -- on which we need to find the latest record.
  • Ensure the to aggregate for Date is Max of that Date column and ADD another metric as "ALL" to later expand all the rows in the table.
  • Expand the table in column ALL
  • After that filter the column for date filter where it equals to the Max Date column
  • Remove columns that are no longer needed i.e Max Date and Count of Row 
amitchandak
Super User
Super User

@KG1 , refer if this blog can help

https://exceleratorbi.com.au/remove-duplicates-keep-last-record-power-query/

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

Check out the May 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

May 2025 Monthly Update

Fabric Community Update - May 2025

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