Forum

"Group by" with fir...
 
Notifications
Clear all

"Group by" with first names combining in ascending order)

5 Posts
2 Users
0 Reactions
303 Views
(@jycccwjc)
Posts: 64
Estimable Member
Topic starter
 

I use Group By to combine kids' first names. I hope to accomplish it by combining of first names in ascending order such that:

Chloe & Charlotte---> Charlotte & Chloe

Cody & Benjamin & Abigail---> Abigail & Benjamin & Cody

Dessiah & Sinai & Antonio---> Antonio & Dessiah & Sinai

Stella & Liliana & Logan--> Liliana & Logan & Stella

I did sort them before I group them, but I don't know why the results are not what I expected.

Appreciate your time and help.

 

JIm

 
Posted : 30/08/2022 3:06 pm
Riny van Eekelen
(@riny)
Posts: 1194
Member Moderator
 

Hi Jim,

Have a look at the attached file. I 've added a query that does what you need. Key in this solution is to sort the children's first names and wrap the step in a Table.Buffer function. That fixes the sorted table in memory. Then you simply group by Customer and Text.Combine by First1. Just two steps after connecting to the Source.

Riny 

 
Posted : 30/08/2022 11:40 pm
(@jycccwjc)
Posts: 64
Estimable Member
Topic starter
 

Riny,

It works great. Thanks.

I Googled it and it seems to me that PowerQuery has a tendency to try and be too efficient, in this case, removing a bunch of rows and sorting the smaller dataset. We add Table.Buffer to force PowerQuery to actually sort the whole table.

Is my understanding correct?

 
Posted : 31/08/2022 12:59 pm
Riny van Eekelen
(@riny)
Posts: 1194
Member Moderator
 

Not sure what you mean by "PQ trying to be too efficient". As in Excel, there are many ways to achieve the same end result. Some are more efficient than others. Table.Buffer is needed, for instance, when you notice that sorting goes wrong. More about that in the link below.

https://docs.microsoft.com/en-us/powerquery-m/table-buffer

 
Posted : 31/08/2022 2:45 pm
(@jycccwjc)
Posts: 64
Estimable Member
Topic starter
 

Got it. Thanks!

 
Posted : 01/09/2022 12:35 pm
Share: