let
T1 = Excel.CurrentWorkbook(){[Name="TableA"]}[Content],
T2 = Excel.CurrentWorkbook(){[Name="TableB"]}[Content],
MQ = Table.NestedJoin(T1, {"Task ID"}, T2, {"Task ID"}, "Table2", JoinKind.FullOuter),
ExpandedTable = Table.ExpandTableColumn(MQ, "Table2", {"Task ID", "Amount"}, {"Task ID.1", "Amount.1"}),
SortRows = Table.Sort(ExpandedTable,{{"Task ID", Order.Ascending}}),
GroupedRows = Table.Group(SortRows, {"Task ID"}, {{"Data", each _, type table [Task ID=text, Amount=number, Task ID.1=text, Amount.1=number]}}),
AddedCustomColumn = Table.AddColumn(GroupedRows, "Custom", each Table.AddIndexColumn([Data],"Row",1,1)),
RemovedColumns = Table.SelectColumns(AddedCustomColumn,{"Custom"}),
ExpandedCustomColumn = Table.ExpandTableColumn(RemovedColumns, "Custom", {"Task ID", "Amount", "Task ID.1", "Amount.1", "Row"}, {"Task ID", "Amount", "Task ID.1", "Amount.1", "Row"}),
FilterFor1 = Table.AddColumn(ExpandedCustomColumn, "Custom", each if [Row]=1 then [Task ID] else null),
#"Added Custom" = Table.AddColumn(FilterFor1, "Custom.1", each if [Row]=1 then [Amount] else null),
RemoveCol = Table.RemoveColumns(#"Added Custom",{"Task ID","Row","Amount"}),
MoveColumn = Table.ReorderColumns(RemoveCol,{"Custom", "Custom.1","Task ID.1", "Amount.1"}),
RenamedColumns = Table.RenameColumns(MoveColumn,{{"Custom", "Task ID"},{"Custom.1","Amount"}})
in
RenamedColumns