Groupby in many to many relationship

dbonilla0331

New Member
Joined
Apr 19, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Our system create groupIDS (unique and incremental) to group activity between customerIDs. So I can have multiple groupids containing multiple customers.
Using powerquery, preferable, I would like to list all the customers that have a relationship and stack them in a new index/group.
Ex. My Table
GroupIDCustomer
1200
1201
2200
2203
3200
3400
4500
4510
4520

Output

IndexCustomer
1200
1201
1200
1203
1200
1400
2500
2510
2520
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I may be little dense, but I cannot figure out the relationships you are showing between the Input and Output. Perhaps you could explain in more detail what the criteria are to arrive at the shown output.
 
Upvote 0
I may be little dense, but I cannot figure out the relationships you are showing between the Input and Output. Perhaps you could explain in more detail what the criteria are to arrive at the shown output.
the output will stack up all CustomerIDs that have shared a relationship with GroupID. So for example, groupid 1, had customers 200 and 201, then groupID 2, had 200 and 203, I need to group then in a 3rd group and stack up them together, Index 1 = 200, 201 and 203.
 
Upvote 0
Why is 400 in Index 1? Doesn't seem to be part of the 200's. Am I missing something here?
 
Upvote 0
maybe this

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"GroupID"}, {{"All", each _, type table [GroupID=number, Customer=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.SelectRows(#"Grouped Rows", (x)=> [All][Customer]{0} = x[All][Customer]{0} )),
    #"Removed Duplicates" = Table.Distinct(#"Added Custom", {"Custom"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Duplicates",{"GroupID", "All"}),
    #"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 1, 1, Int64.Type),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Index", "Custom", {"All"}, {"Custom.All"}),
    #"Expanded Custom.All" = Table.ExpandTableColumn(#"Expanded Custom", "Custom.All", {"Customer"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Custom.All",{"Index", "Customer"})
in
    #"Reordered Columns"
 
Upvote 0

Forum statistics

Threads
1,215,364
Messages
6,124,507
Members
449,166
Latest member
hokjock

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