How do I merge tables with common ID values without having value repeat ?

NZEmersen

New Member
Joined
Jan 6, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have three tables showing Plant, Material and Labour quantities from each of my crews on site,

The tables are linked by unique identifiers or "Shift Report Numbers", however, multiple items assigned to each unique identifier. For example:

Shift Report Number Date Job Code Labour Resource Hours
0000101/01/21XYZHarry 2
0000101/01/21XYZJimmy3
0000101/01/21XYZHarold3

Shift Report Number MaterialQuantity
00001Aggregate200

Shift Report NumberPlantQuantity
00001Roller1
00001Digger1
00001Plate Compactor0.5

I would like to merge the tables, however, have each observation from each table only occur once in the combined result and be justified to the top of the table. i.e:

Shift Report NumberDateJob CodeLabour ResourceHoursMaterialQuantityPlantQuantity
0000101/01/21XYZHarry2Aggregate200Roller1
0000101/01/21XYZJimmy3Digger1
0000101/01/21XYZHarold3Plate Compactor0.5

The individual tables are imported from local files on my computer using Power Queries. I have tried to use Power Queries and Full Outer Merges to combine the tables but have found that observations are repeated from each table.

How can I produce the desired result ?

Many Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Shift Report NumberDateJob CodeLabour ResourceHours
0000101/01/2021XYZHarry2
0000101/01/2021XYZJimmy3
0000101/01/2021XYZHarold3
Shift Report NumberMaterialQuantity
00001Aggregate200
Shift Report NumberPlantQuantity
00001Roller1
00001Digger1
00001Plate Compactor0.5
Shift Report NumberDateJob CodeLabour ResourceHoursMaterialQuantityPlantQuantity.1
0000101/01/2021XYZHarry2Aggregate200Roller1
0000101/01/2021XYZJimmy3Digger1
0000101/01/2021XYZHarold3Plate Compactor0.5

Power Query:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1),
    Join1 = Table.NestedJoin(Index,{"Index"},Table2,{"Index"},"Table2",JoinKind.LeftOuter),
    Expand1 = Table.ExpandTableColumn(Join1, "Table2", {"Material", "Quantity"}, {"Material", "Quantity"}),
    Join2 = Table.NestedJoin(Expand1,{"Index"},Table3,{"Index"},"Table3",JoinKind.LeftOuter),
    Expand2 = Table.ExpandTableColumn(Join2, "Table3", {"Plant", "Quantity"}, {"Plant", "Quantity.1"}),
    RC = Table.RemoveColumns(Expand2,{"Index"}),
    Type = Table.TransformColumnTypes(RC,{{"Date", type date}})
in
    Type

Power Query:
// Table2
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1)
in
    Index

Power Query:
// Table3
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1)
in
    Index
 
Upvote 0
Shift Report NumberDateJob CodeLabour ResourceHours
0000101/01/2021XYZHarry2
0000101/01/2021XYZJimmy3
0000101/01/2021XYZHarold3
Shift Report NumberMaterialQuantity
00001Aggregate200
Shift Report NumberPlantQuantity
00001Roller1
00001Digger1
00001Plate Compactor0.5
Shift Report NumberDateJob CodeLabour ResourceHoursMaterialQuantityPlantQuantity.1
0000101/01/2021XYZHarry2Aggregate200Roller1
0000101/01/2021XYZJimmy3Digger1
0000101/01/2021XYZHarold3Plate Compactor0.5

Power Query:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1),
    Join1 = Table.NestedJoin(Index,{"Index"},Table2,{"Index"},"Table2",JoinKind.LeftOuter),
    Expand1 = Table.ExpandTableColumn(Join1, "Table2", {"Material", "Quantity"}, {"Material", "Quantity"}),
    Join2 = Table.NestedJoin(Expand1,{"Index"},Table3,{"Index"},"Table3",JoinKind.LeftOuter),
    Expand2 = Table.ExpandTableColumn(Join2, "Table3", {"Plant", "Quantity"}, {"Plant", "Quantity.1"}),
    RC = Table.RemoveColumns(Expand2,{"Index"}),
    Type = Table.TransformColumnTypes(RC,{{"Date", type date}})
in
    Type

Power Query:
// Table2
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1)
in
    Index

Power Query:
// Table3
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1)
in
    Index


Apologies,

I am quite new to using power queries in the way you have shown,

How to I implement the above code ?

Many Thanks,
 
Upvote 0
:biggrin:
How to I implement the above code ?
you don't need to do this
just add Index (the same style) to each table
then merge Table1 and Table2 by Index, Expand without ID and Index and then merge Table1 and Table3 by Index and Expand without ID and Index
Remove unnecessary column - first Index
that's all
 
Upvote 0

Forum statistics

Threads
1,223,749
Messages
6,174,275
Members
452,553
Latest member
red83

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