Power Query - Table.Group & Text.Combine

Gwill1983

Board Regular
Joined
Oct 24, 2018
Messages
123
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have previously used these features to create an order summary report as below:


CustomerEmail AddressOrders
Joe Bloggs380370
Jon Smith380139; 380004
Alan Partridge380536; 380621

This table uses the syntax = Table.Group(#"Filtered Rows", {"Supplier", "Email Address"}, {{"Outstanding Purchase Orders", each Text.Combine([PO Number], "; "), type nullable text}})

The raw data that we are provided now breaks each order down into outstanding items so I would like to adapt this to include the items when creating this report. Ideally this would look something like the below:



CustomerEmail AddressOrdersItems
Joe Bloggs380370Part A; Part B; Part C
Jon Smith380139; 380004Part C; Part D x 2
Alan Partridge380536; 380621Part A x 3

The column in the raw data is named 'Part Description', but I cannot work out how to add the items column and then combine the parts to show multiples etc. I have tried to re-add the {{"Outstanding Purchase Orders", each Text.Combine([PO Number], "; ") section of the syntax and adjust this, but it doesnt work.

If anybody has any ideas how to make this work you would be my hero!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You need to add a new list within the list:

Code:
= Table.Group(#"Changed Type", {"Supplier", "Email Address"}, {{"Outstanding Purchase Orders", each Text.Combine(List.Distinct([PO Number]), "; "), type nullable text}, {"Item list", each Text.Combine([Items], "; "), type nullable text}})

I added List.Distinct as I guess you need to avoid duplicates in the Orders column
 
Upvote 0
Solution
You need to add a new list within the list:

Code:
= Table.Group(#"Changed Type", {"Supplier", "Email Address"}, {{"Outstanding Purchase Orders", each Text.Combine(List.Distinct([PO Number]), "; "), type nullable text}, {"Item list", each Text.Combine([Items], "; "), type nullable text}})

I added List.Distinct as I guess you need to avoid duplicates in the Orders column
Thanks for this.

It works exactly how I wanted it to.

Do you know if there is anyway of ensuring that duplicates in the item column show as multiples rather than duplicate entries? For instance, at the moment, if a customer had 3 orders outstanding all containing the same item it would show as below:

CustomerEmail AddressOrdersItems
Joe Bloggs380370; 380371; 380372Part A; Part A; Part A

Is it possible to adjust this to show as this:


CustomerEmail AddressOrdersItems
Joe Bloggs380370; 380371; 380372Part A x 3
 
Upvote 0
Yes - something like:

Power Query:
= Table.Group(#"Changed Type", {"Supplier", "Email Address"}, {{"Outstanding Purchase Orders", each Text.Combine(List.Distinct([PO Number]), "; "), type nullable text}, {"Item list", each Text.Combine(List.Distinct(List.Transform([Items], (y)=> let cnt = List.Count(List.Select(_[Items], (x)=>x=y)) in if cnt = 1 then y else y & " x " & Text.From(cnt))), "; "), type nullable text}})

should work. (there may well be simpler options; I'm not an M guru!)
 
Upvote 0
Perfect! You seem to be an M guru to me! :)

Thanks for your help
 
Upvote 0
Glad we could help! :)
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top