Appending data based on reference from multiple tables using Power Query

RajaR

New Member
Joined
Aug 29, 2020
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Dears,
I've a custom requirement for product Bill of material (BOM) creation. I've two tables of data (Table1 - Level1 BOM & Table2 - Level2 BOM).
I need output as per Table3.

Below I've uploaded images of the 3 tables, using XL2BB add-in.

Also I've very little knowledge in Power query. Attached are sample files, wherein in actual I've to work with >20k rows of data for both Table1 & 2.
It shall be truly helpful, if you can share the source code (to be used in Power query) for this requirement.

Thanks in advance.
Regards,

Raja
WC BOM_Test Book1.xlsx
ABCDE
1Table 1 - Level1 BOM
2FG CodeFG DescriptionLevel1 CodeLevel1 DescriptionLevel1 Qty
33SAA100001R1Product 101AAR9300807Basic CB2
43SAA100001R1Product 101ABR8220001Plate1
53SAA100001R1Product 101ABR8222910KIT 2pcs1
63SAA100001R1Product 101AAR9300810Frontal2
73SAA222222R1Product 222AAR9300901Basic Breaker1
83SAA222222R1Product 222AAR9300910Facia2
93SAA222222R1Product 222ABR8220005Cover1
103SAA222222R1Product 222ABR8222805Terminal3
Master BOM


WC BOM_Test Book1.xlsx
ABCDE
12Table 2 - Level2 BOM
13Level1 CodeLevel1 DescriptionLevel2 CodeLevel2 DescriptionLevel2 Qty
14AR9300807Basic CB1SDR00001CT3
15AR9300807Basic CB1SDR00002Wiring2
16AR9300807Basic CB1SDR00003Tube1
17BR8220001Plate1SDR00004Nut1
18BR8222910KIT 2pcsYSDR00001Cover1
19BR8222910KIT 2pcsYSDR00002Washer2
20BR8222910KIT 2pcsYSDR00003Screw2
21AR9300810FrontalZSDR00001ROD2
22AR9300810FrontalZSDR00002Tie2
23AR9300901Basic BreakerPSDR00001CT 88
24AR9300901Basic BreakerPSDR00002RP1
25AR9300901Basic BreakerPSDR00003TU1
26AR9300910FaciaRSDR00001Label2
27AR9300910FaciaRSDR00002Sleeve1
28BR8222805TerminalPPSR00001Washer 13
29BR8222805TerminalPPSR00002Bolt3
Master BOM


WC BOM_Test Book1.xlsx
ABCDEF
32Table 3 - Required Output
33FG CodeFG DescriptionBOM CodeBOM DescriptionQtyRemarks
343SAA100001R1Product 101AAR9300807Basic CB2From Table1 - Level1 Code, Description, Qty
353SAA100001R1Product 101A1SDR00001CT6From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
363SAA100001R1Product 101A1SDR00002Wiring4From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
373SAA100001R1Product 101A1SDR00003Tube2From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
383SAA100001R1Product 101ABR8220001Plate1From Table1 - Level1 Code, Description, Qty Also, this has no level2 BOM details….
393SAA100001R1Product 101ABR8222910KIT 2pcs1From Table1 - Level1 Code, Description, Qty
403SAA100001R1Product 101AYSDR00001Cover1From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
413SAA100001R1Product 101AYSDR00002Washer2From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
423SAA100001R1Product 101AYSDR00003Screw2From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
433SAA100001R1Product 101AAR9300810Frontal2From Table1 - Level1 Code, Description, Qty
443SAA100001R1Product 101AZSDR00001ROD2From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
453SAA100001R1Product 101AZSDR00002Tie2From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
463SAA222222R1Product 222AAR9300901Basic Breaker1From Table1 - Level1 Code, Description, Qty
473SAA222222R1Product 222APSDR00001CT 88From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
483SAA222222R1Product 222APSDR00002RP1From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
493SAA222222R1Product 222APSDR00003TU1From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
503SAA222222R1Product 222AAR9300910Facia2From Table1 - Level1 Code, Description, Qty
513SAA222222R1Product 222ARSDR00001Label4From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
523SAA222222R1Product 222ARSDR00002Sleeve2From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
533SAA222222R1Product 222ABR8220005Cover1From Table1 - Level1 Code, Description, Qty Also, this has no level2 BOM details….
543SAA222222R1Product 222ABR8222805Terminal3From Table1 - Level1 Code, Description, Qty
553SAA222222R1Product 222APPSR00001Washer 19From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
563SAA222222R1Product 222APPSR00002Bolt9From Table2 - Level2 Code, Description, (Level2 Qty * Level1 Qty)
Master BOM
Cell Formulas
RangeFormula
C34:E34C34=C3
C35:D37C35=C14
E35:E37E35=E14*$E$3
C38:E39C38=C4
C40:D42C40=C18
E40:E42E40=E18*$E$5
C43:E43C43=C6
C44:E45C44=C21
C46:E46C46=C7
C47:D49C47=C23
E47:E49E47=E23*$E$7
C50:E50C50=C8
C51:D52C51=C26
E51:E52E51=E26*$E$8
C53:E54C53=C9
C55:D56C55=C28
E55:E56E55=E28*$E$10
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Dears,
Can anyone help me on this requirement - using Power query??
Thanks.

Regards,
Raja
 
Upvote 0
Please try


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Renamed = Table.RenameColumns(Source,{{"Level1 Code", "BOM Code"}, {"Level1 Description", "BOM Description"}, {"Level1 Qty", "Qty"}}),
    Join = Table.NestedJoin(Renamed, {"BOM Code"}, Table.RenameColumns(Excel.CurrentWorkbook(){[Name="Table2"]}[Content],{{"Level2 Code", "BOM Code"}, {"Level2 Description", "BOM Description"}, {"Level2 Qty", "Qty"}}), {"Level1 Code"}, "L2", JoinKind.LeftOuter),
    AddBOM = Table.AddColumn(Join, "BOM", each let 
        a =Table.TransformColumns(Table.SelectColumns([L2], List.Skip(Table.ColumnNames([L2]),2)),{"Qty", (x)=> x * [Qty] }),
        b = Table.InsertRows(a,0, {Record.SelectFields(_, List.Range(Record.FieldNames(_),2,3))} )
        in b),
    RemovedColumns = Table.RemoveColumns(AddBOM,{"BOM Description", "Qty", "L2"}),
    ExpandedBOM = Table.ExpandTableColumn(RemovedColumns, "BOM", {"BOM Code", "BOM Description", "Qty"}, {"BOM Code.1", "BOM Description", "Qty"})
in
    ExpandedBOM
 
Upvote 0
Solution
Dear Bo_Ry,
Thanks a lot for your quick response & support.... It's working fabulously.
I will check for mass data & revert in case of any query.

Once again, thanks.

Regards,
Raja
 
Upvote 0

Forum statistics

Threads
1,215,633
Messages
6,125,922
Members
449,274
Latest member
mrcsbenson

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