Hi @Mo.jo.jo,
Seems @MK3010 beat me to it but since my solution is different thought I would share it any way…
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRCkpNz8zPUzAEMs1NgIQhCMA5SrE6+BQaAWkjkIgRAYXGQNrUgAiFINrEAq7QCFkhyDYzc7CVEDeCORA3GiMrBNlmDuIbA9WZgWi4gbjVmcM4BAw0AtFmUL/EAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Region ID" = _t, #"Region Name" = _t, #"Region Manager ID" = _t, #"Group ID" = _t, #"Group Manager ID" = _t, #"Group Type" = _t]),
#"Added Custom" = Table.AddColumn(Source, "IsRegionManager", each List.Contains( List.Distinct( Source[Region Manager ID] ), [Group Manager ID] ), type logical),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Region Name"}, {{"AllRows", each _, type table [Region ID=nullable text, Region Name=nullable text, Region Manager ID=nullable text, Group ID=nullable text, Group Manager ID=nullable text, Group Type=nullable text, IsRegionManager=logical]}}),
TransformNestedTables = Table.AddColumn(#"Grouped Rows", "Custom", each
let
myTable = [AllRows],
AddListGroups = Table.AddColumn(myTable, "List Groups", each if [IsRegionManager] = true then myTable[Group ID] else Table.SelectRows(myTable, (BT)=> BT[IsRegionManager] = false )[Group ID], type list),
ExpandListGroups = Table.ExpandListColumn(AddListGroups, "List Groups"),
ChangeType = Table.TransformColumnTypes(ExpandListGroups,{{"List Groups", type text}})
in
ChangeType, type table )[[Custom]],
ExpandNestedTables = Table.ExpandTableColumn(TransformNestedTables, "Custom", {"Region ID", "Region Name", "Region Manager ID", "Group ID", "Group Manager ID", "Group Type", "IsRegionManager", "List Groups"}, {"Region ID", "Region Name", "Region Manager ID", "Group ID", "Group Manager ID", "Group Type", "IsRegionManager", "List Groups"})[[Group Manager ID], [List Groups]],
ChangeType = Table.TransformColumnTypes(ExpandNestedTables,{{"Group Manager ID", type text}, {"List Groups", type text}}),
RenameColumns = Table.RenameColumns(ChangeType,{{"Group Manager ID", "User ID"}, {"List Groups", "Access to Groups"}})
in
RenameColumns
.
I added a column to identify Group Managers
Added a Group By step on Region Name
Next I created a list with Group ID’s based on a condition for each nested table
Table.AddColumn(myTable, "List Groups", each
if [IsRegionManager] = true then myTable[Group ID] else
Table.SelectRows(myTable, (BT)=> BT[IsRegionManager] = false )[Group ID], type list)
Expanded that table and did some clean up with this result.
Here’s your sample file. Creating a bridge table.pbix (18.0 KB)
I hope this is helpful.