Data --> Pivot Table

therealjdj

New Member
Joined
Jul 8, 2013
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Ok team -- I got a question to make Data useable in a Pivot Table.

So let's say I get a report that looks like the top table in the attached image. It has a breakdown of customers, what they purchased, when we booked the order, and when we invoiced the order. From what I can tell this data is not usable in a Pivot Table.
It would have to be modified to look more like the second table. Where each individual order has a line for each transaction.
The end is the sort of pivot table I would like to have.

Is this correct?
 

Attachments

  • Pivot Table.png
    Pivot Table.png
    33.4 KB · Views: 13

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Cannot manipulate data in a picture. Can you reload using XL2BB so that we don't have to retype all your data to help you.
 
Upvote 0
Cannot manipulate data in a picture. Can you reload using XL2BB so that we don't have to retype all your data to help you.
Here you go:


test.xlsx
ABCDEFGHIJKLMNOP
1BookingsSales
22022202320222023
3CustomerProductOctNovDecJanFebMarchOctNovDecJanFebMarch
41A$ 10.00$ 5.00$ 5.00
51C$ 4.00$ 3.00$ 1.00
61G$ 2.00$ 1.00$ 1.00
72G$ 8.00$ 1.00$ 6.00$ 1.00
82A$ 4.00$ 4.00
93B$ 20.00$ 5.00$ 5.00$ 5.00$ 5.00
104A$ 10.00$ 10.00
114G$ 4.00$ 4.00
12
13
14CustomerProductYearMonthBookingSales
151A2022Oct$ 10.00
161A2022Dec$ 5.00
171A2023Jan$ 5.00
181C2023Jan$ 4.00
191C2023Jan$ 3.00
201C2023Feb$ 1.00
211G2022Nov$ 2.00
221G2022Dec$ 1.00
231G2023March$ 1.00
24
test3
 
Upvote 0
A Power Query Solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Transposed Table" = Table.Transpose(Source),
    #"Filled Down" = Table.FillDown(#"Transposed Table",{"Column1", "Column2"}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Filled Down", {{"Column2", type text}}, "en-US"),{"Column1", "Column2"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged"),
    #"Merged Columns1" = Table.CombineColumns(#"Merged Columns",{"Merged", "Column3"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged.1"),
    #"Transposed Table1" = Table.Transpose(#"Merged Columns1"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"::Customer", "::Product"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Attribute.1", "Attribute.2", "Attribute.3"}),
    #"Sorted Rows" = Table.Sort(#"Split Column by Delimiter",{{"::Customer", Order.Ascending}, {"::Product", Order.Ascending}, {"Attribute.2", Order.Ascending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows", "Sales", each if Text.StartsWith([Attribute.1],"Sales") then [Value] else null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Bookings", each if Text.StartsWith([Attribute.1],"Book") then [Value] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Attribute.1", "Value"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"::Customer", "::Product", "Attribute.2", "Attribute.3", "Bookings", "Sales"})
in
    #"Reordered Columns"

::Customer::ProductAttribute.2Attribute.3BookingsSales
1A2022Dec5
1A2022Oct10
1A2023Jan5
1C2023Feb1
1C2023Jan3
1C2023Jan4
1G2022Dec1
1G2022Nov2
1G2023March1
2A2023Feb4
2A2023March4
2G2022Dec8
2G2023March1
2G2023Jan1
2G2023Feb6
3B2022Dec5
3B2022Nov20
3B2023March5
3B2023Feb5
3B2023Jan5
4A2022Oct10
4A2023Feb10
4G2023March4
4G2023Jan4
 
Upvote 0
Solution
Thank you!
That code worked great on this example. Now I can hopefully take what you showed me and expand it to my larger problem that I am trying to solve.

Thanks again! I have never yused Power Query but am looking forward to learning the tool
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,109
Members
453,021
Latest member
Justyna P

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