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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
RyanL-EIS
Frequent Visitor

Latest Record in Group via Query Editor

We are trying to get the latest record/row in a group via Query Editor.  After we expand the group and we filter on the latest record, it filters the entire dataset and not within the group.  Please see below.

 

Capture1.PNG

 

let
Data = Source{[Name="Data"]}[Data],
dbo_PercentOfProceeds = Data{[Schema="dbo",Item="PercentOfProceeds"]}[Data],
#"Grouped Rows" = Table.Group(#"Removed Duplicates", {"settleID", "productionDate"}, {{"SettleID-Statement_Group", each _, type table}}),
#"Expanded SettleID-Statement_Group" = Table.ExpandTableColumn(#"Grouped Rows", "SettleID-Statement_Group", {"fileAndPage", "statementDate"}, {"SettleID-Statement_Group.fileAndPage", "SettleID-Statement_Group.statementDate"}),

#"Latest Records" = Table.SelectRows(#"Expanded SettleID-Statement_Group", let latest = List.Max(#"Expanded SettleID-Statement_Group"[#"SettleID-Statement_Group.statementDate"]) in each [#"SettleID-Statement_Group.statementDate"] = latest)

 

in

#"Latest Records"

 

Any suggestions?

 

Thanks for your help!

 

2 ACCEPTED SOLUTIONS
ImkeF
Community Champion
Community Champion

You should select them before you expand the group. So try modifying your group-command like this:

 

#"Grouped Rows" = Table.Group(#"Removed Duplicates", {"settleID", "productionDate"}, {{"SettleID-Statement_Group", each _, type table}, {"Max", each List.Max([statementDate])} }),

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

MarcelBeug
Community Champion
Community Champion

Somehow this post was duplicated, I provided a similar, but slightly different answer in the other version: https://community.powerbi.com/t5/Desktop/Latest-Record-in-Group-via-Query-Editor/td-p/225190

 

Especially for @ImkeF refering to our discussion about "types" elsewhere (but also interesting for others 🙂 😞

Table.Group with option "All Rows" generates code with "type table", which means that all columns in the nested tables have data type any. This is a pity (or a shame?), because such tables have the same structure as the original table, so e.g. in this example: if type table is replaced with Value.Type(#"Removed Duplicates"), then the nested tables have the same type as the original table and the columns will be expanded with the correct data type instead of any..

 

This would also be an additional suggestion for the solution I provided in the other post I linked above.

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
ImkeF
Community Champion
Community Champion

You should select them before you expand the group. So try modifying your group-command like this:

 

#"Grouped Rows" = Table.Group(#"Removed Duplicates", {"settleID", "productionDate"}, {{"SettleID-Statement_Group", each _, type table}, {"Max", each List.Max([statementDate])} }),

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

MarcelBeug
Community Champion
Community Champion

Somehow this post was duplicated, I provided a similar, but slightly different answer in the other version: https://community.powerbi.com/t5/Desktop/Latest-Record-in-Group-via-Query-Editor/td-p/225190

 

Especially for @ImkeF refering to our discussion about "types" elsewhere (but also interesting for others 🙂 😞

Table.Group with option "All Rows" generates code with "type table", which means that all columns in the nested tables have data type any. This is a pity (or a shame?), because such tables have the same structure as the original table, so e.g. in this example: if type table is replaced with Value.Type(#"Removed Duplicates"), then the nested tables have the same type as the original table and the columns will be expanded with the correct data type instead of any..

 

This would also be an additional suggestion for the solution I provided in the other post I linked above.

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.

June 2025 community update carousel

Fabric Community Update - June 2025

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