Query or Xlookup: filling in material from assembly list

shredr

New Member
Joined
Jan 23, 2007
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I have to file a regulatory report
To prep I need to fill in what parts are made or assembled from.

I have a list of about a thousand P/N that needs the material column populated (ListA).

Some PN are made from a single item, some are assemblies.

To fill this I need to query / lookup a second list that has almost 10000 items (ListB)
Some of the items in ListB are assemblies, so I need to put all assembly items to the right of the PN in ListA

Logically, I need to compare PN between the lists, and if PN matches, fill in the cell to the right.
If the PN in ListB has several instances of a PN, I need to keep filling cells to the right until there is not a match for the PN, then move on to the next PN in ListA
Does that make sense? (example attached)

Thanks!

table to be filled

example to fill in material list.xlsx
ABCDEFGHIJ
1PNMaterial
21Awant to populate ColB using data from other tab, what's shown is desired results
32Bif multiple items used for assy, want to fill addional cells to the right
43C
54D
65EEEEEE
76F
87g
98HHhHhHHhHHHHhHH
109J
1110KKJ
12
PN matl to be filled



Table to use to lookup materials

example to fill in material list.xlsx
ABCD
1PNmatl used / assy itms
21A
32B
43C
54D
65E
75EE
85EEE
96f
107g
118H
128Hh
138HhH
148HhHH
158HHhHH
169J
1710K
1810KJ
19
20
21
Sheet2
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello, could you please share here what version of Excel are you using?
 
Upvote 0
Adjust ranges as necessary.

EXCEL
ABCDEFGHIJKLM
1PNMaterialPNmatl used / assy itms
21A 1A
32B 2B
43C 3C
54D 4D
65EEEEEE5E
76F 5EE
87g 5EEE
98HHhHhHHhHHHHhHH6f
109J 7g
1110KKJ8H
128Hh
138HhH
148HhHH
158HHhHH
169J
1710K
18EEEEE10KJ
Sheet1
Cell Formulas
RangeFormula
C2:C5,C7:C8,C10:C11,C9:F9,C6:D6C2=IFERROR(DROP(REDUCE("",$M$2:$M$18,LAMBDA(s,c,IF(UPPER(LEFT(c))=UPPER(B2),HSTACK(s,c),s))),,2),"")
 
Upvote 0
An alternative is with Power Query. Join the two tables and then pivot the data.
Book2
ABCDEFGHIJKL
1PNMaterialPNmatl used / assy itmsPN12345
21A1A1A
32B2B2B
43C3C3C
54D4D4D
65E5E5EEEEEE
76F5EE6f
87g5EEE7g
98H6f8HHhHhHHhHHHHhHH
109J7g9J
1110K8H10KKJ
128Hh
138HhH
148HhHH
158HHhHH
169J
1710K
1810KJ
Sheet1


Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    T2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    MQ = Table.NestedJoin(T1, {"PN"}, T2, {"PN"}, "T3", JoinKind.FullOuter),
    #"Added Custom" = Table.AddColumn(MQ, "Custom", each Table.AddIndexColumn([T3],"Index",1,1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"PN", "matl used  / assy itms", "Index"}, {"PN", "matl used  / assy itms", "Index"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Custom", {{"Index", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expanded Custom", {{"Index", type text}}, "en-US")[Index]), "Index", "matl used  / assy itms")
in
    #"Pivoted Column"
 
Upvote 0
Not sure if it would make a difference performance-wise. But, this is how I would do it with PQ.

Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    T2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    MQ = Table.NestedJoin(T1, {"PN"}, T2, {"PN"}, "T3", JoinKind.FullOuter),
    Transform = Table.TransformColumns(MQ,{{"T3", each if List.Count(_[#"matl used  / assy itms"]) > 1 then List.Skip(_[#"matl used  / assy itms"]) else null}}),
    Split = Table.SplitColumn(Table.TransformColumns(Transform,{{"T3", each if _ <> null then Text.Combine(_,"~") else null}}),"T3",Splitter.SplitTextByDelimiter("~"),{"1"..Text.From(List.Max(List.Transform(Transform[T3],each try List.Count(_) otherwise 0)))})
in
    Split
 
Upvote 0
Never used power query before, I'll have to take a look at how it works...how steep is the learning cureve?
 
Upvote 0
Maybe not as steep as VBA. I don't know. It's pretty approachable. And just like VBA, you can definitely get into the weeds with it and deep dive. But, for general stuff, like I said, I think it's pretty easy to get into.
 
Upvote 0
I found that this book is a great primer.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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