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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Amarinho777
New Member

filter multiple rows of same ID by max date

Hello,

 

I have a table with many columns, one of them is an ID and one of them contains dates. An ID can have multiple rows. I would like the table to show only the row of an ID with the max date.

 

PBi question.PNG

 

So after applying the Power Query step(s), I would like the above table to only showthe rows in green.

 

Thanks in advance!

1 ACCEPTED SOLUTION
m_alireza
Solution Specialist
Solution Specialist

Hi @Amarinho777 ,

Please see below query. You can copy the query and place it in advanced editor, taking the parts you need to recreate it in your table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZYwxCoAwDAD/0rmQNFhbHyA4io7iIBJE0ApV/2/TSXQ87rhhUNZapRVZMAYITZWgnzY+1ai/kjBB02XjnBPjwKAYSlCHZQ3McQ1LTrz3khSApZzl1MZjviPvHK53QoD5/0vGBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Department = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"Department", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"MaxDate", each List.Max([Date]), type date}, {"All", each _, type table [ID=nullable number, Date=nullable date, Department=nullable text]}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Date", "Department"}, {"Date", "Department"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded All", each ([MaxDate] = [Date])),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"MaxDate"})
in
    #"Removed Columns"


 I also linked a sample pbix file for your reference: 
https://drive.google.com/file/d/1YJmSFV6E51eHyi942K4jSdVh7atwmSQw/view?usp=sharing 

Sample output: 
date and department.png

View solution in original post

1 REPLY 1
m_alireza
Solution Specialist
Solution Specialist

Hi @Amarinho777 ,

Please see below query. You can copy the query and place it in advanced editor, taking the parts you need to recreate it in your table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZYwxCoAwDAD/0rmQNFhbHyA4io7iIBJE0ApV/2/TSXQ87rhhUNZapRVZMAYITZWgnzY+1ai/kjBB02XjnBPjwKAYSlCHZQ3McQ1LTrz3khSApZzl1MZjviPvHK53QoD5/0vGBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Department = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"Department", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"MaxDate", each List.Max([Date]), type date}, {"All", each _, type table [ID=nullable number, Date=nullable date, Department=nullable text]}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Date", "Department"}, {"Date", "Department"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded All", each ([MaxDate] = [Date])),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"MaxDate"})
in
    #"Removed Columns"


 I also linked a sample pbix file for your reference: 
https://drive.google.com/file/d/1YJmSFV6E51eHyi942K4jSdVh7atwmSQw/view?usp=sharing 

Sample output: 
date and department.png

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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