cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
joshua1990
Post Prodigy
Post Prodigy

Max Value per Order based on two columns

Hi experts!

 

I have an order table that shows me several rows per Order:

Order NrColumn 1Column 2Value
100213358300050
100213359000045
1012133205
1022133005

 

Using Power Query I would like to group/ pivot this table by Order Nr and Value. And the Value is based on the Max of Column 1 and Column 2.

How is that possible within PQ?

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @joshua1990 

 

What's the expected output based on this sample data?

 

Best Regards,
Community Support Team _ Jing

ValtteriN
Super User
Super User

Hi,

I am not sure if I understood correctly but here is a commented PQ that might be of use.

Start data:

ValtteriN_0-1639064504364.png

PQ:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNKBkhbGBkqxOqhilnAxIyDPGCwGEzEGsk1gIrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Order Number" = _t, C1 = _t, C2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Order Number", Int64.Type}, {"C1", Int64.Type}, {"C2", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Value", each List.Max({[C1],[C2]})), //Here we get the max of columns1 and 2
#"Grouped Rows" = Table.Group(#"Added Custom", {"Order Number"}, {{"Value", each List.Sum([Value]), type nullable number}}) //Here we group the values based on order
in
#"Grouped Rows"

 

I hope this helps and if it does consider accepting this as a solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors