Excel Pivot Multiple Columns

Africat

New Member
Joined
Aug 5, 2018
Messages
3
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ItemList[/TD]
[TD]Colour1[/TD]
[TD]Colour2[/TD]
[TD]Colour3[/TD]
[TD]Colour4[/TD]
[TD]Colour5[/TD]
[TD]Colour6[/TD]
[TD]Colour7[/TD]
[TD]Colour8[/TD]
[/TR]
[TR]
[TD]Item 1[/TD]
[TD]Blue[/TD]
[TD]Yellow[/TD]
[TD]Purple[/TD]
[TD]Green[/TD]
[TD]Orange[/TD]
[TD]Red[/TD]
[TD]Cyan[/TD]
[TD]White[/TD]
[/TR]
[TR]
[TD]Item 2[/TD]
[TD]Black[/TD]
[TD]Magenta[/TD]
[TD]Cyan[/TD]
[TD]Yellow[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Hi I'm new here so sorry about the unconventional formatting. I have a item table with different coloured paints. I have created a unique list of colours and I am trying to create a relationship between the UniqueColourList and all 8 colours cloumns on the item table so that when expanded shows only the item numbers that has that colour. I've gotten it to "work" by creating a relationship with all 8 colours (some sorta crazy 1-to-many x 8).
Practical use would be to expand the pivot table at blue and see all the Items that require blue so that forecasting can be done on how much blue paint to order & is require for exisitng orders etc.

I was wondering if there is some better method to get a cleaner result without powerpivot and with powerpivot?
Thanks

[TABLE="class: grid, width: 10, align: left"]
<tbody>[TR]
[TD]UniqueColourList[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]Black[/TD]
[/TR]
[TR]
[TD]Yellow[/TD]
[/TR]
[TR]
[TD]....[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Here are two possibilities....
Using Power Query (Get & Transform):
I named the data range: rngColors
- Select the range and use: Data.From_Table (The Power Query editor will open)
- Promote the first row to headers
- Select the first column and use Unpivot Other Columns
- Remove the first two columns (ItemList, Attribute)
- Remove duplicates

These are the M-language steps:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="rngColors"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ItemList", type text}, {"Colour1", type text}, {"Colour2", type text}, {"Colour3", type text}, {"Colour4", type text}, {"Colour5", type text}, {"Colour6", type text}, {"Colour7", type text}, {"Colour8", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"ItemList"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"ItemList", "Attribute"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns")
in
    #"Removed Duplicates"

This is a manual approach:
- Use this Excel 2003 keyboard shortcut: ALT+DPP (to open a create Pivot Table window)
- Check: Multiple Consolidation Ranges.....Click: Next
- Check: I will create the page fields........Click: Next
- Select the data range....Click: Add....Click: Finish
- Remove the Column and Row fields
- Double-click the Value amount (to create a new sheet with the UN-pivoted data)
- Remove the first two columns
- Use Remove Duplicates (on the table ribbon tab)

Is that something you can work with?
 
Upvote 0
Hi Ron,

Thanks for the response. I'm not sure if I have followed all the steps correctly.
I can get the unique list of colors but I am having difficulty creating a pivot table relating the two.

Ideally I am trying to make a pivot table below:
When Blue is expanded it shows only item 1 since it requires Blue
When Black is expanded it shows only item 2 since it requires Black
When Yellow is expanded it shows item 1 and item 2 since both require Yellow
I don't have trouble doing this if for example each item only has Colour1, but when trying to also relate all 8 colours i seem to be having difficulty.

Blue
Item 1
Black
Item 2
Yellow
Item 1
Item 2
....

<colgroup><col style="width:48pt" width="64" span="2"> </colgroup><tbody>
[TD="width: 128, colspan: 2"]UniqueColour Pivot[/TD]

</tbody>

The only other way I can think of doing this is by rearranging the fields
Item Column
Item 1 - Blue
Item 1 - Yellow
Item
 
Upvote 0
Continued...
The only other way I can think of doing this is by rearranging the fields
Item Column Colour
Item 1 Blue
Item 1 Yellow
Item 1 Purple
.....

But i would like to keep the item column as a key field with no duplicates
 
Upvote 0
If you used Power Query...Getting the grouping is easy:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="rngColors"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ItemList", type text}, {"Colour1", type text}, {"Colour2", type text}, {"Colour3", type text}, {"Colour4", type text}, {"Colour5", type text}, {"Colour6", type text}, {"Colour7", type text}, {"Colour8", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"ItemList"}, "Attribute", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns1", {"Value"}, {{"Colors", each _, type table}}),
    #"Expanded Colors" = Table.ExpandTableColumn(#"Grouped Rows", "Colors", {"ItemList"}, {"ItemList"})
in
    #"Expanded Colors"

Then, if you want that data in a pivot table....
- Insert.Pivot_Table
- Use an External Data source
....Select the query you built
....Click: Open
....Continue building the pivot table as you normally would by putting the colors and items in ROWS

Does that help?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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