Power Query help - transpose

ashley1984

New Member
Joined
Mar 31, 2018
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to transpose a column with several data points (Sales Value, Sales Volume, Unit Price etc) into separate columns, so a column for each data point.

I also have weekly dates (data is pulled off weekly and currently runs for 104 weeks) that the data needs to then correspond back with. I have uploaded some images of the data, the first image should be what the data currently looks like and the second how I want it be. I've changed the data into a table and opened Power Query and tried the Unpivot option but not had much luck.

Any help would be appreciated.

PowerQuery Current.JPG
PowerQuery ToBe.JPG
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
post data in copyable form, eg. via XL2BB


Is this better? The data how it currently is:

PowerQuery Help.xlsx
BCDEFGH
3Product codeItem NameMeasure03/06/2019 10/06/2019 17/06/2019 17/06/20192
46420Product ASales Units 125,955 129,466 59,905 48,879
51188Product ASales Value£249,361£254,021£135,676£120,803
69070Product AProduct Price £ 1.98 £ 1.96 £ 2.26 £ 2.47
78552Product BSales Units 24,607 26,978 68,211 95,584
83126Product BSales Value£60,819£66,077£131,300£177,797
97476Product BProduct Price £ 2.47 £ 2.45 £ 1.92 £ 1.86
107330Product CSales Units 20,380 19,813 16,314 16,757
114470Product CSales Value£50,445£49,134£40,505£41,383
126467Product CProduct Price £ 2.48 £ 2.48 £ 2.48 £ 2.47
134131Product DSales Units 19,610 18,026 6,956 4,659
141447Product DSales Value£37,353£35,334£15,046£11,083
153086Product DProduct Price £ 1.90 £ 1.96 £ 2.16 £ 2.38
Current Data
Cell Formulas
RangeFormula
E6:H6,E15:H15,E12:H12,E9:H9E6=E5/E4



and the data how I want it post Power Query:

PowerQuery Help.xlsx
BCDEFG
3Product codeItem NameDateSales ValueSales UnitsProduct Price
49070Product A03/06/2019 £ 249,361.11 125,955 £ 1.98
57476Product B03/06/2019 £ 60,819.45 24,607 £ 2.47
66467Product C03/06/2019 £ 50,445.35 20,380 £ 2.48
73086Product D03/06/2019 £ 37,352.72 19,610 £ 1.90
89070Product A 10/06/2019 £ 254,020.73 129,466 £ 1.96
97476Product B 10/06/2019 £ 66,076.67 26,978 £ 2.45
106467Product C 10/06/2019 £ 49,133.81 19,813 £ 2.48
113086Product D 10/06/2019 £ 35,334.04 18,026 £ 1.96
129070Product A 17/06/2019 £ 135,676.01 59,905 £ 2.26
137476Product B 17/06/2019 £ 131,299.93 68,211 £ 1.92
146467Product C 17/06/2019 £ 40,504.66 16,314 £ 2.48
153086Product D 17/06/2019 £ 15,045.71 6,956 £ 2.16
169070Product A 17/06/2019 £ 120,802.65 48,879 £ 2.47
177476Product B 17/06/2019 £ 177,797.00 95,584 £ 1.86
186467Product C 17/06/2019 £ 41,382.64 16,757 £ 2.47
193086Product D 17/06/2019 £ 11,083.41 4,659 £ 2.38
To Be Data
 
Upvote 0
Unpivot columns with Dates via PQ then from the ribbon: Insert - Pivot Table
 
Upvote 0
or
Item NameAttributeSales USales VProd Price
Product A03/06/2019125955249361.111.979763487
Product A10/06/2019129466254020.731.962065175
Product A17/06/2019108784256478.664.736316055
Product B03/06/20192460760819.452.471632056
Product B10/06/20192697866076.672.449279784
Product B17/06/2019163795309096.933.785021017
Product C03/06/20192038050445.352.475237978
Product C10/06/20191981349133.812.479877353
Product C17/06/20193307181887.34.952389299
Product D03/06/20191961037352.721.904779194
Product D10/06/20191802635334.041.960170864
Product D17/06/20191161526129.124.541907698

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Unpivot = Table.Unpivot(Source, {"03/06/2019", "10/06/2019", "17/06/2019", " 17/06/2019"}, "Attribute", "Value"),
    Type = Table.TransformColumnTypes(Unpivot,{{"Attribute", type date}}),
    Pivot = Table.Pivot(Type, List.Distinct(Type[Measure]), "Measure", "Value", List.Sum),
    Group = Table.Group(Pivot, {"Item Name", "Attribute"}, {{"Sales U", each List.Sum([Sales Units]), type number}, {"Sales V", each List.Sum([Sales Value]), type number}, {"Prod Price", each List.Sum([Product Price]), type number}}),
    Sort = Table.Sort(Group,{{"Item Name", Order.Ascending}, {"Attribute", Order.Ascending}})
in
    Sort

or Pivot Attribute by Value
 
Last edited:
Upvote 0
with rounded values and proper sorting
Item NameAttributeSales USales VProd Price
Product A03/06/2019125955249361.111.98
Product B03/06/20192460760819.452.47
Product C03/06/20192038050445.352.48
Product D03/06/20191961037352.721.9
Product A10/06/2019129466254020.731.96
Product B10/06/20192697866076.672.45
Product C10/06/20191981349133.812.48
Product D10/06/20191802635334.041.96
Product A17/06/2019108784256478.664.74
Product B17/06/2019163795309096.933.79
Product C17/06/20193307181887.34.95
Product D17/06/20191161526129.124.54

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Unpivot = Table.Unpivot(Source, {"03/06/2019", "10/06/2019", "17/06/2019", " 17/06/2019"}, "Attribute", "Value"),
    Type = Table.TransformColumnTypes(Unpivot,{{"Attribute", type date}}),
    Pivot = Table.Pivot(Type, List.Distinct(Type[Measure]), "Measure", "Value", List.Sum),
    Group = Table.Group(Pivot, {"Item Name", "Attribute"}, {{"Sales U", each List.Sum([Sales Units]), type number}, {"Sales V", each List.Sum([Sales Value]), type number}, {"Prod Price", each List.Sum([Product Price]), type number}}),
    Round = Table.TransformColumns(Group,{{"Sales U", each Number.Round(_, 2), type number}, {"Sales V", each Number.Round(_, 2), type number}, {"Prod Price", each Number.Round(_, 2), type number}}),
    Sort = Table.Sort(Round,{{"Attribute", Order.Ascending}, {"Item Name", Order.Ascending}})
in
    Sort
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,789
Messages
6,174,579
Members
452,573
Latest member
Cpiet

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