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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors