Transpose data ready for pivot table

mattchewie

New Member
Joined
Sep 17, 2018
Messages
4
Hi all,

I have data on 3 different tabs. 1 for stock on hand, 1 for sales, and i need to convert them to the the way i have it on the "Data for Pivot" tab. The data i have cannot be changed as this is the format i get it in. I basically want to combine SOH and sales by store, but then be able to have it in a line listing for a pivot table.
I have tried transposing it which works, but i need the line duplicated to show all models. The real data i have has around 200 stores, and 500 models, so i need a dump and process method... ideas?

an example below:

Stock on hand tab

[TABLE="width: 320"]
<tbody>[TR]
[TD="class: xl63, width: 64"][/TD]
[TD="class: xl63, width: 64"]Store A[/TD]
[TD="class: xl63, width: 64"]Store B[/TD]
[TD="class: xl63, width: 64"]Store C[/TD]
[TD="class: xl63, width: 64"]Store D[/TD]
[/TR]
[TR]
[TD="class: xl63"]Model 1[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]4[/TD]
[/TR]
[TR]
[TD="class: xl63"]Model 2[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]4[/TD]
[/TR]
[TR]
[TD="class: xl63"]Model 3[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]4[/TD]
[/TR]
[TR]
[TD="class: xl63"]Model 4[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]4[/TD]
[/TR]
</tbody>[/TABLE]

Sales Tab
[TABLE="width: 320"]
<tbody>[TR]
[TD="width: 64"][/TD]
[TD="width: 64"]Store A[/TD]
[TD="width: 64"]Store B[/TD]
[TD="width: 64"]Store C[/TD]
[TD="width: 64"]Store D[/TD]
[/TR]
[TR]
[TD]Model 1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Model 2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Model 3[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Model 4[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 256"]
<tbody>[TR]
[TD="width: 64"]Store[/TD]
[TD="width: 64"]Model[/TD]
[TD="width: 64"]SOH[/TD]
[TD="width: 64"]Sales[/TD]
[/TR]
[TR]
[TD]Store A[/TD]
[TD]Model 1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store A[/TD]
[TD]Model 2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store A[/TD]
[TD]Model 3[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store A[/TD]
[TD]Model 4[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store B[/TD]
[TD]Model 1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Store B[/TD]
[TD]Model 2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Store B[/TD]
[TD]Model 3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Store B[/TD]
[TD]Model 4[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Store C[/TD]
[TD]Model 1[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store C[/TD]
[TD]Model 2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store C[/TD]
[TD]Model 3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store C[/TD]
[TD]Model 4[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Store D[/TD]
[TD]Model 1[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Store D[/TD]
[TD]Model 2[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Store D[/TD]
[TD]Model 3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Store D[/TD]
[TD]Model 4[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
try PowerQuery

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Model[/td][td=bgcolor:#5B9BD5]Store A[/td][td=bgcolor:#5B9BD5]Store B[/td][td=bgcolor:#5B9BD5]Store C[/td][td=bgcolor:#5B9BD5]Store D[/td][td][/td][td=bgcolor:#5B9BD5]Model[/td][td=bgcolor:#5B9BD5]Store A[/td][td=bgcolor:#5B9BD5]Store B[/td][td=bgcolor:#5B9BD5]Store C[/td][td=bgcolor:#5B9BD5]Store D[/td][td][/td][td=bgcolor:#70AD47]store[/td][td=bgcolor:#70AD47]Model[/td][td=bgcolor:#70AD47]soh[/td][td=bgcolor:#70AD47]sales[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Model 1[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
2​
[/td][td=bgcolor:#DDEBF7]
3​
[/td][td=bgcolor:#DDEBF7]
4​
[/td][td][/td][td=bgcolor:#DDEBF7]Model 1[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
2​
[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
2​
[/td][td][/td][td=bgcolor:#E2EFDA]Store A[/td][td=bgcolor:#E2EFDA]Model 2[/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Model 2[/td][td]
1​
[/td][td]
2​
[/td][td]
3​
[/td][td]
4​
[/td][td][/td][td]Model 2[/td][td]
1​
[/td][td]
2​
[/td][td]
1​
[/td][td]
2​
[/td][td][/td][td]Store A[/td][td]Model 4[/td][td]
1​
[/td][td]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Model 3[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
2​
[/td][td=bgcolor:#DDEBF7]
3​
[/td][td=bgcolor:#DDEBF7]
4​
[/td][td][/td][td=bgcolor:#DDEBF7]Model 3[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
2​
[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
2​
[/td][td][/td][td=bgcolor:#E2EFDA]Store A[/td][td=bgcolor:#E2EFDA]Model 3[/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Model 4[/td][td]
1​
[/td][td]
2​
[/td][td]
3​
[/td][td]
4​
[/td][td][/td][td]Model 4[/td][td]
1​
[/td][td]
2​
[/td][td]
1​
[/td][td]
2​
[/td][td][/td][td]Store A[/td][td]Model 1[/td][td]
1​
[/td][td]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]Store B[/td][td=bgcolor:#E2EFDA]Model 3[/td][td=bgcolor:#E2EFDA]
2​
[/td][td=bgcolor:#E2EFDA]
2​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]Store B[/td][td]Model 4[/td][td]
2​
[/td][td]
2​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]Store B[/td][td=bgcolor:#E2EFDA]Model 1[/td][td=bgcolor:#E2EFDA]
2​
[/td][td=bgcolor:#E2EFDA]
2​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]Store B[/td][td]Model 2[/td][td]
2​
[/td][td]
2​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]Store C[/td][td=bgcolor:#E2EFDA]Model 3[/td][td=bgcolor:#E2EFDA]
3​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]Store C[/td][td]Model 4[/td][td]
3​
[/td][td]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]Store C[/td][td=bgcolor:#E2EFDA]Model 1[/td][td=bgcolor:#E2EFDA]
3​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]Store C[/td][td]Model 2[/td][td]
3​
[/td][td]
1​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]Store D[/td][td=bgcolor:#E2EFDA]Model 4[/td][td=bgcolor:#E2EFDA]
4​
[/td][td=bgcolor:#E2EFDA]
2​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]Store D[/td][td]Model 1[/td][td]
4​
[/td][td]
2​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]Store D[/td][td=bgcolor:#E2EFDA]Model 2[/td][td=bgcolor:#E2EFDA]
4​
[/td][td=bgcolor:#E2EFDA]
2​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]Store D[/td][td]Model 3[/td][td]
4​
[/td][td]
2​
[/td][/tr]
[/table]


UnPivot each table then Merge them


Merge:
Code:
[SIZE=1]let
    Source = Table.NestedJoin(Table1,{"Model", "Attribute"},Table2,{"Model", "Attribute"},"Table2",JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Value"}, {"Table2.Value"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Table2",{"Attribute", "Model", "Value", "Table2.Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Value", "soh"}, {"Table2.Value", "sales"}, {"Attribute", "store"}}),
    #"Sorted Rows" = Table.Sort(#"Renamed Columns",{{"store", Order.Ascending}})
in
    #"Sorted Rows"[/SIZE]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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