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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
JānisB
Frequent Visitor

How to keep rows with max value within another column value group

I have a dataset

 

fileidvalue
2023-07-31_wert.csv55545
2023-07-27_wert.csv55540
2023-07-15_wert.csv55535
2023-07-30_uiop.csv44435
2023-07-10_uiop.csv44430

 

I want to keep only rows with max date (or lates file, etc.) from file name within id

 

Result shoud be

fileidvalue
2023-07-31_wert.csv55545
2023-07-30_uiop.csv44435

 

How can filter this in Power Query?

1 ACCEPTED SOLUTION
ToddChitt
Super User
Super User

So from your example for Id = 555, the winner (row to keep) is the first one because it has the max value, but you also want to include the details (like the file colum) from that row.

Question: Can you be sure that each ID will have ONE and ONLY ONE MAX(VALUE)?

 

If so, try this:

DUPLICATE the data set. 

On the duplicate, do a GROUP BY on Id column, and take an aggregate of MAX of the Value column.

Now JOIN this table with the original table. Do an INNER JOIN so that you only get matching records. Match on the ID and MAX(Value) = Value.




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
G-newbie
New Member

I had the same issue, but with different versions of a document and only wanted the line items from the latest version.

I grouped by maximum version number as below

Then expanded the new details column (Table).

This creates a duplicate line item for each version.

I found the original version column in the expanded table then added conditional column (I called mine Keep_Remove). If [MaxV] column = [Version_No] column then keep else remove. 

Filter out "remove" from the new column

 

Hope this helps.

Gnewbie_0-1704295721694.png

Gnewbie_5-1704296702175.png

 

Gnewbie_1-1704295806820.png

Gnewbie_2-1704295845886.png

Gnewbie_3-1704295886120.png

Gnewbie_4-1704295952623.png

Result:

Gnewbie_7-1704297042649.png

 

 

 

 

ToddChitt
Super User
Super User

So from your example for Id = 555, the winner (row to keep) is the first one because it has the max value, but you also want to include the details (like the file colum) from that row.

Question: Can you be sure that each ID will have ONE and ONLY ONE MAX(VALUE)?

 

If so, try this:

DUPLICATE the data set. 

On the duplicate, do a GROUP BY on Id column, and take an aggregate of MAX of the Value column.

Now JOIN this table with the original table. Do an INNER JOIN so that you only get matching records. Match on the ID and MAX(Value) = Value.




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.