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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MrPingu
Frequent Visitor

Return only rows with max value from specific column

I am trying to only get the max values from a certain column in a table
Data looks like this:
SalesOrderArchive
SalesOrderNo ;  Version_No ;MoreColumns
SO1 ; 1 ; Datalines
SO1 ; 2 ; Datalines
SO2 ; 1 ; Datalines
SO3; 1 ; Datalines
SO3; 2 ; Datalines
SO3; 3 ; Datalines

I want for every disctinct SalesOrderNo. the max version so output should be
SalesOrderNo ;  Version_No ;MoreColumns
SO1 ; 2 ; Datalines
SO2 ; 1 ; Datalines
SO3; 3 ; Datalines




I tried to do the following but it's only returning the max value of VersionNo

SalesLinesArchive_table2 = List.Max(VerkooporderarchiefSalesLinesArchive_table[Version_No])



1 ACCEPTED SOLUTION

If you 'Group By' SalesOrderNo and include 'All Rows'

 

Annotation 2019-06-20 GroupByMax.png

 

then Expand the table that results.

You will have to remove duplicates and tidy as necessary

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Add index row and filter out index 1.

marcelhenrique
Regular Visitor
v-frfei-msft
Community Support
Community Support

Hi @MrPingu ,

 

Gourp by should work. 

 

Capture.PNG

M code for your reference.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCvY3VNJRAuGUxJLEnMy8VKVYHZiwEaawEXbVxriFsRgCEjZGEY4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Sales = _t, #"Version NO" = _t, More = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales", type text}, {"Version NO", Int64.Type}, {"More", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Version NO"}, {{"max", each List.Max([Version NO]), type number}, {"more", each List.Max([More]), type text}})
in
    #"Grouped Rows"
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
HotChilli
Super User
Super User

If you want to return the row where Version_No is largest.

Table.Max(#"Promoted Headers", "Version_No")

where #"Promoted Headers" is the table.

You can then extract the SalesOrderNo

Maybe I didn't fromulat my question well enough.

I want for every  disctinct SalesOrderNo. the max version so output should be
SO1 ; 2 ; Datalines
SO2 ; 1 ; Datalines
SO3; 3 ; Datalines

If you 'Group By' SalesOrderNo and include 'All Rows'

 

Annotation 2019-06-20 GroupByMax.png

 

then Expand the table that results.

You will have to remove duplicates and tidy as necessary

In my opinion, @Anonymous's solution below is simpler: simply a) sort table, then b) add an Index, c) filter Index number. I tried Grouping function; I was NOT able to get this to work using standard Group By: the Max command does NOT choose the value ascociated (same row?) with Max of for instance date. The trick is in your last comments; use the All Rows, then 'clean up'. You then need to use a 'Max.Table' command. By which time you are in the weeds of PowerQuery, per this video: How to Group By Maximum Value using Table.Max in Power Query - YouTube  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors