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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
powerbidev123
Solution Sage
Solution Sage

How to get the latest record and remove older one

Hi all

 

In the power query I have 2 columns 

Date and Id.

Sample dataset is below:

 

Date.                          Id

01/01/2025.               101

01/09/2025.                101

 

 

  • The id column contains duplicate and i want to basically remove the record that has the older date i.e 01/01/2025. How can i achieve that in power query?

 

2 ACCEPTED SOLUTIONS
samratpbi
Super User
Super User

Hi, If you have 2 columns only and then better to group by ID column and take the Max of the date.

Below is the dataset I took:

samratpbi_0-1758830432046.png

 

then done a Group By

samratpbi_1-1758830468431.png

Final output

samratpbi_2-1758830492909.png

 

Hope this helps to resolve your problem. If it does, then please mark it as solution.

Thanks - Samrat

 

View solution in original post

lbendlin
Super User
Super User

The safest way to do that is to use the grouping feature

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMtU31jcyMDJVitUBCRkChQwM9YEISRCkzkTf2ACbQkuoYCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"ID", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Date", each List.Max([Date]), type nullable date}})
in
    #"Grouped Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

 

View solution in original post

3 REPLIES 3
powerbidev123
Solution Sage
Solution Sage

Hi @lbendlin , @samratpbi  thanks for pitching in . I created a new column that using list.max that gives max of the date else the older date will be blank 

lbendlin
Super User
Super User

The safest way to do that is to use the grouping feature

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMtU31jcyMDJVitUBCRkChQwM9YEISRCkzkTf2ACbQkuoYCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"ID", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Date", each List.Max([Date]), type nullable date}})
in
    #"Grouped Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

 

samratpbi
Super User
Super User

Hi, If you have 2 columns only and then better to group by ID column and take the Max of the date.

Below is the dataset I took:

samratpbi_0-1758830432046.png

 

then done a Group By

samratpbi_1-1758830468431.png

Final output

samratpbi_2-1758830492909.png

 

Hope this helps to resolve your problem. If it does, then please mark it as solution.

Thanks - Samrat

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.