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
Terrassa
Helper I
Helper I

Find value of a column based on the maximum value of another

I have a table with purchase orders. Each order has several items, and each item has several sequences (every time an item is modified it generates a new sequence). There's a column with the status of each sequence.

 

In Power Query I need to find the status of the latest sequence of each item of an order.

 

This is an example of the table:

OrderItemSequenceStatus
100010A
100011B
100012C
100020C
100021B
100030B
100031C
100110A
100111B
100120B

 

This is what I need as a result:

OrderItemSequenceStatus
100012C
100021B
100031C
100111B
100120B

 

The result should be the max sequence for each order/item and its status.

 

Thank you very much for any help that you could provide.

2 ACCEPTED SOLUTIONS
Vijay_A_Verma
Super User
Super User

Insert this step where Source must be replaced by your previous step name

Table.Group(Source, {"Order", "Item"}, {{"Sequence", each List.Max([Sequence])}, {"Status", each Table.Max(_,"Sequence")[Status]}})

A sample code below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIEYhDtqBSrgyIIwk7ogkZA7IwsaATVjiGIod0YqhJD0BBZuyE2Jxlic5Ihku1AwVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order = _t, Item = _t, Sequence = _t, Status = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Order", "Item"}, {{"Sequence", each List.Max([Sequence])}, {"Status", each Table.Max(_,"Sequence")[Status]}})
in
    #"Grouped Rows"

View solution in original post

Thank you very much for your quick answer, it worked perfectly.

 

I understand how the List.Max for the sequence works, but I don't understand the Table.Max for the status. Could you please explain what this command is doing?

View solution in original post

3 REPLIES 3
Vijay_A_Verma
Super User
Super User

Insert this step where Source must be replaced by your previous step name

Table.Group(Source, {"Order", "Item"}, {{"Sequence", each List.Max([Sequence])}, {"Status", each Table.Max(_,"Sequence")[Status]}})

A sample code below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIEYhDtqBSrgyIIwk7ogkZA7IwsaATVjiGIod0YqhJD0BBZuyE2Jxlic5Ihku1AwVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order = _t, Item = _t, Sequence = _t, Status = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Order", "Item"}, {{"Sequence", each List.Max([Sequence])}, {"Status", each Table.Max(_,"Sequence")[Status]}})
in
    #"Grouped Rows"

Thank you very much for your quick answer, it worked perfectly.

 

I understand how the List.Max for the sequence works, but I don't understand the Table.Max for the status. Could you please explain what this command is doing?

Table.Max(_,"Sequence") - This takes the maximum of Sequence field.

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.