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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

Choose the registry with the latest update

Hi, I have a case where I have three records with the same registration ID but with different STATUS and I need to choose the record with the most recent date. Can it be done in Power Query? How could I do it?

YEARMYIDREGISTROESTADO
20229RT2325963Assigned
202210RT2325963Earring
202211RT2325963Earring
20232RT2325963Closed
202210RT9899967Assigned
20232RT9899967Closed

Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @LoloGox ,

I created a sample pbix file(see the attachment), please check if that is what you want.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlLSUbIE4qAQI2MjU0szYyDbsbg4Mz0vNUUpVgeuxtAATZFrYlFRZl46ihpD/GpAQkZoSpxz8oux2mRpYWlpaWaOxTkIYxBqYMbEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [YEAR = _t, MY = _t, IDREGISTRO = _t, ESTADO = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"YEAR", Int64.Type}, {"MY", Int64.Type}, {"IDREGISTRO", type text}, {"ESTADO", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"IDREGISTRO"}, {{"Most recent date", each List.Max([YEAR]), type nullable number}, {"Details", each _, type table [YEAR=nullable number, MY=nullable number, IDREGISTRO=nullable text, ESTADO=nullable text]}}),
    #"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows", "Details", {"YEAR", "MY", "ESTADO"}, {"YEAR", "MY", "ESTADO"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Details", "Flag", each if [Most recent date]=[YEAR] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Flag] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Most recent date", "Flag"})
in
    #"Removed Columns"

yingyinr_0-1675841040793.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @LoloGox ,

I created a sample pbix file(see the attachment), please check if that is what you want.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlLSUbIE4qAQI2MjU0szYyDbsbg4Mz0vNUUpVgeuxtAATZFrYlFRZl46ihpD/GpAQkZoSpxz8oux2mRpYWlpaWaOxTkIYxBqYMbEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [YEAR = _t, MY = _t, IDREGISTRO = _t, ESTADO = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"YEAR", Int64.Type}, {"MY", Int64.Type}, {"IDREGISTRO", type text}, {"ESTADO", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"IDREGISTRO"}, {{"Most recent date", each List.Max([YEAR]), type nullable number}, {"Details", each _, type table [YEAR=nullable number, MY=nullable number, IDREGISTRO=nullable text, ESTADO=nullable text]}}),
    #"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows", "Details", {"YEAR", "MY", "ESTADO"}, {"YEAR", "MY", "ESTADO"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Details", "Flag", each if [Most recent date]=[YEAR] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Flag] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Most recent date", "Flag"})
in
    #"Removed Columns"

yingyinr_0-1675841040793.png

Best Regards

amitchandak
Super User
Super User

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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