Help rearranging dataset (pivot, lookup, or something else?)

Matrovsky

New Member
Joined
Sep 6, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Sorry for the uninformative title; I'm not sure what to call the thing I'm trying to accomplish. I'm importing data from a PDF and hope to rearrange them into a more useful structure.

I have a list of widgets, grouped by the subwidgets they're made of. So the initial import looks something like this (formatting added for readability):
_____________________________________________________________________________________________
#SET#05
Widget1
Widget2
Widget12
Widget39

TotalQty Subwidget Description Details
Qty05.A SubwidgetA DescriptionA DetailsA
Qty05.B SubwidgetB DescriptionB DetailsB
Qty05.C
SubwidgetC DescriptionC DetailsC
Qty05.D
SubwidgetD DescriptionD DetailsD



#SET#14
Widget4
Widget19
Widget68

TotalQty Subwidget Description Details
Qty14.A SubwidgetA DescriptionA DetailsA

Qty14.B SubwidgetB DescriptionB DetailsB
Qty14.F SubwidgetF DescriptionF DetailsF


#SET#35
Widget41

TotalQty Subwidget Description Details
Qty35.A SubwidgetA DescriptionA DetailsA
Qty35.B SubwidgetC DescriptionC DetailsC
Qty35.F
SubwidgetF DescriptionF DetailsF
Qty35.H
SubwidgetH DescriptionH DetailsH

_____________________________________________________________________________________________

The end goal is a table of widgets (rows) vs. subwidgets (columns) indicating which are included in which:
WidgetSetSubASubBSubCSubDSubFSubH
W105TRUETRUETRUETRUEFALSEFALSE
W205TRUETRUETRUETRUEFALSEFALSE
W1205TRUETRUETRUETRUEFALSEFALSE
W3905TRUETRUETRUETRUEFALSEFALSE
W414TRUETRUEFALSEFALSETRUEFALSE
W914TRUETRUEFALSEFALSETRUEFALSE
W6814TRUETRUEFALSEFALSETRUEFALSE
W4135TRUEFALSETRUEFALSETRUETRUE

I've extracted a table showing the widgets & subwidgets associated with each set:
SetWidgetsQTySubwidgets
05W1--
05W2--
05W12--
05W39--
05-Qty05.AA
05-Qty05.BB
05-Qty05.CC
05-Qty05.DD
14W4--
14W9--
14W68--
14-Qty14.AA
14-Qty14.BB
14-Qty14.FF
35W41--
35-Qty35.AA
35-Qty35.CC
35-Qty35.FF
35-Qty35.HH

...and I can collapse those into unique lists, records, or tables as needed, and have used them to create the main structure of the desired table:
WidgetSetSubASubBSubCSubDSubFSubH
W105
W205
W1205
W3905
W414
W914
W6814
W4135
...but then I don't know which lookup and/or pivot operations are needed to fill it with the correct values. Can anybody help?

Thank you in advance for any help you're willing to offer!

BONUS QUESTION: If possible, I would love to have the quantity of each subwidget needed instead of a Boolean, but I didn't want to distract from the main question in case it adds a bunch of complication:
WidgetSetSubASubBSubCSubDSubFSubH
W105Qty05.A/COUNT(Set05)Qty05.B/COUNT(Set05)Qty05.B/COUNT(Set05)Qty05.B/COUNT(Set05)00
W205Qty05.A/COUNT(Set05)Qty05.B/COUNT(Set050Qty05.B/COUNT(Set05)Qty05.B/COUNT(Set05)00
W1205Qty05.A/COUNT(Set05)Qty05.B/COUNT(Set05)Qty05.B/COUNT(Set05)Qty05.B/COUNT(Set05)00
W3905Qty05.A/COUNT(Set05)Qty05.B/COUNT(Set05)Qty05.B/COUNT(Set05)Qty05.B/COUNT(Set05)00
W414Qty14.A/COUNT(Set14)Qty14.B/COUNT(Set14)00Qty14.B/COUNT(Set14)0
W914Qty14.A/COUNT(Set14)Qty14.B/COUNT(Set14)00Qty14.B/COUNT(Set14)0
W6814Qty14.A/COUNT(Set14)Qty14.B/COUNT(Set14)00Qty14.B/COUNT(Set14)0
W4135Qty35.A/COUNT(Set35)0Qty35.B/COUNT(Set35)0Qty35.B/COUNT(Set35)Qty35.B/COUNT(Set35)
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
@Matrovsky , here is true and false part
Power Query:
let
    wdg = (tbl) => 
        [widgets = List.Select(tbl[Widgets], each _ <> "-"),
        subwidgets = List.Select(tbl[Subwidgets], each _ <> "-"), 
        z = Table.FromList(widgets, Splitter.SplitByNothing(), {"Widgets"} & subwidgets, true)][z],
    // Source is your extracted table
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content], 
    all_subw = List.Sort(List.Distinct(List.Select(Source[Subwidgets], each _ <> "-"))),
    group = Table.Group(Source, "Set", {"x", wdg}), 
    xpand = Table.ExpandTableColumn(group, "x", {"Widgets"} & all_subw), 
    result = Table.TransformColumns(xpand, {}, (x) => x ?? false)
in
    result
 
Upvote 0
Hi @Matrovsky,
An attempt, Source is your extracted table.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    cols = Table.ColumnNames(Source),
    a = Table.FillDown(Table.TransformColumns(Source, {} , (x)=> Replacer.ReplaceValue(x,"-",null)),{cols{1}}),
    b = Table.Group(a, cols{0}, {{"x", each 
        [ 
        x = List.Transform(List.Skip(Table.ToColumns(_)), List.RemoveNulls),
        y = {List.Range(x{0}, 0, List.Count(x{2})), List.Transform(x{1}, each Number.From(Text.Select(_, {"0".."9"}))), List.Transform(x{2}, each "Sub" & Text.From(_))},
        z = Table.FromColumns(y & {List.Repeat({List.Sum(y{1})}, List.Count(y{1}))}, List.Skip(cols) & {"x"})
        ][z]}}),
    c = Table.ExpandTableColumn(b, "x", List.Skip(cols) & {"x"}),
    d = Table.ExpandRecordColumn(Table.Group(c, {cols{1}, cols{0}}, {{"x", each let x = Table.AddColumn(_,"y", each [QTy]/[x]) 
        in Record.FromList(x[y], x[Subwidgets])}}), "x", List.Distinct (c[Subwidgets])),
    Sol = Table.TransformColumns(d, {} , (x)=> Replacer.ReplaceValue(x,null,0))
in
    Sol

Regards
 
Upvote 0
bonus
Power Query:
let
    wdg = (tbl) => 
        [widgets = List.Select(tbl[Widgets], each _ <> "-"),
        subwidgets = List.Select(tbl[Subwidgets], each _ <> "-"),
        qty = List.Buffer(List.Select(tbl[QTy], each _ <> "-")), 
        z = Table.FromList(widgets, (x) => {x} & List.Transform(qty, (w) => w / List.Count(widgets)), {"Widgets"} & subwidgets, true)][z],
    // Source is your extracted table
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content], 
    all_subw = List.Sort(List.Distinct(List.Select(Source[Subwidgets], each _ <> "-"))),
    group = Table.Group(Source, "Set", {"x", wdg}), 
    xpand = Table.ExpandTableColumn(group, "x", {"Widgets"} & all_subw), 
    result = Table.TransformColumns(xpand, {}, (x) => x ?? false)
in
    result
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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