On reflection...the following should be more efficient (still with Excel Table1 as data source
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ChangedTypes = Table.TransformColumnTypes(Source,
{
{"Items", Int64.Type}, {"Quantity", Int64.Type}, {"Process 1", type text}, {"Process 2", type text},
{"Process 3", type text}, {"Process 4", type text}, {"Process 5", type text}
}
),
MergedTables = List.Transform(
{1..List.Count(List.Select(Table.ColumnNames(ChangedTypes), each Text.StartsWith(_,"Process "))) -1},
each
let
TableFrom = Table.RenameColumns(
Table.SelectColumns(ChangedTypes,{"Items","Quantity","Process "&Text.From(_)}),
{"Process "&Text.From(_),"From"}
),
TableTo = Table.RenameColumns(
Table.SelectColumns(ChangedTypes,{"Items","Quantity","Process "&Text.From(_ +1)}),
{"Process "&Text.From(_ +1),"To"}
),
JoinedTables = Table.NestedJoin(TableFrom,"Items", TableTo,"Items", "TableTo", JoinKind.FullOuter),
ExpandedTo = Table.ExpandTableColumn(JoinedTables, "TableTo", {"To"})
in
Table.SelectColumns(ExpandedTo, {"From","To","Quantity"})
),
CombinedTables = Table.Combine(MergedTables)
in
CombinedTables
Sample updated