Forum Discussion
eightbitannotations
Sep 10, 2024Copper Contributor
Match Columns While Making Space for Dupicates
Hi all, I have two sheets with 10,000 rows that I need to match/sort, however, the 2nd set has multiples that need to be matched with a single value from the 1st list. Please see the example I have a...
Lorenzo
Sep 11, 2024Silver Contributor
With Power Query in attached file. Query1:
let
Source = Table.NestedJoin(
Table1, {"LIST1"},
Table2, {"LIST2"},
"MERGED_2",
JoinKind.LeftOuter
),
AddedList2 = Table.AddColumn(Source, "LIST2", each
List.Combine( Table.ToColumns([MERGED_2]) ),
List.Type
),
RemovedMergedTable = Table.RemoveColumns(AddedList2, {"MERGED_2"}),
ExpandedList2 = Table.AddColumn(RemovedMergedTable, "EXPANDED2", each
if List.IsEmpty([LIST2]) then {null} else [LIST2],
List.Type
),
RemovedList2 = Table.RemoveColumns(ExpandedList2, {"LIST2"}),
ExpandedList1 = Table.AddColumn(RemovedList2, "EXPANDED1", each
if List.IsEmpty([EXPANDED2])
then {[LIST1]}
else {[LIST1]} & List.Repeat({null}, List.Count([EXPANDED2]) -1),
List.Type
),
RemovedList1 = Table.RemoveColumns(ExpandedList1, {"LIST1"}),
ListsToTable = Table.FromColumns(
List.Combine(
{
{ List.Combine(RemovedList1[EXPANDED1]) },
{ List.Combine(RemovedList1[EXPANDED2]) }
}
),
{"LIST1", "LIST2"}
)
in
ListsToTable