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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

keep the most recent record

dear all

 

I'm starting with PowerBI//PowerQuery. I will push data from an ERP to make dashboards. I have a specific case that is the following:

* i will get a file every week that extract data from the current month.

 

I neeed to store this lines and will have duplicated rows. but in some cases, the "duplicates row" means it is the same order but with updated fields. So I need to keep only the most recent field. I have made a key and have the date. I need just to know how to keep only the most recent.

 

here's a sample :

 

Pierre63_0-1658495062639.png

 

In this sample, I have 2 lines with the same Key (field's name is CLE). I need to keep the most recent.

thank you

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcoxDoAgDAXQq5DOkPTXoNIN1E1PQLj/NexmBKa3vFpJWCTwFgTO7RqTxtXlhzzdYGYzU/P/lpQxtNI3W6KQb8E8+gXM2jlpy9guau0F", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date modified" = _t, CLE = _t, #"Type BL" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date modified", type datetime}, {"CLE", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"CLE"}, {{"Max", each List.Max([Date modified]), type nullable datetime}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"CLE", "Date modified"}, #"Grouped Rows", {"CLE", "Max"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"CLE"}, {"CLE.1"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Grouped Rows", each ([CLE.1] <> null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"CLE.1"})
in
    #"Removed Columns"

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcoxDoAgDAXQq5DOkPTXoNIN1E1PQLj/NexmBKa3vFpJWCTwFgTO7RqTxtXlhzzdYGYzU/P/lpQxtNI3W6KQb8E8+gXM2jlpy9guau0F", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date modified" = _t, CLE = _t, #"Type BL" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date modified", type datetime}, {"CLE", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"CLE"}, {{"Max", each List.Max([Date modified]), type nullable datetime}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"CLE", "Date modified"}, #"Grouped Rows", {"CLE", "Max"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"CLE"}, {"CLE.1"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Grouped Rows", each ([CLE.1] <> null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"CLE.1"})
in
    #"Removed Columns"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.