Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
L70F
Helper I
Helper I

Transpose PIVOT table with dynamic headings to a list

Hi,

I have searched for possible solution among other posts, but unfortunataly didn't find what can help my problem. 

 

We get price lists in pivot format where quantity values mentiones as the headings for different columns. These differ every time we get a new price list. For further analysis with these, I need to transform PIVOT matrix table into a list format. I tried to use the PQ function unpivot, but it makes the column headings to fixed values, which makes this not work when I use a new table as input.

 

Now I use a VBA macro for this purpose, but  I want to get a solution in Power Query. 

I really appreciate your help with PQ codes, thank you. 

 

Example input1:

Row Labels12345
5367370176.65    
8701135808302.356108.95042.14281.9 
870120980  1797.61493.1 
870168680    971.25
870304080     
870304801    273

 

Example output 1:

Row LabelsQtyPrice
53673701176.65
87011358018302.35
87011358026108.9
87011358035042.1
87011358044281.9
87012098031797.6
87012098041493.1
8701686805971.25
8703048015273

 

Next time the input might be as exampe 2:

Row Labels451015202544506075
870306280      74.55   
8703158011697.85         
99137427  376.95330.75303.45     
99137455 486.15379.05343.35      
99138432  199.5153.3130.2     
99138441     58.8 44.1 39.9

 

Output example2:

Row LabelsQtyPrice
8703062804474.55
87031580141697.85
9913742710376.95
9913742715330.75
9913742720303.45
991374555486.15
9913745510379.05
9913745515343.35
9913843210199.5
9913843215153.3
9913843220130.2
991384412558.8
991384415044.1
991384417539.9
1 ACCEPTED SOLUTION

Thank you Pijush for your link. I have watched it and solved my problem. 

BR//Larissa

View solution in original post

7 REPLIES 7
camargos88
Community Champion
Community Champion

@L70F ,

 

You just need to use the Unpivot other columns:

 

Capture.PNGCapture.PNGCapture.PNG

 

Check the attached file.

 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Hi, thank you for your reply, but it doesn't work to simply do unpivot other columns. Because if I would enter my second example data instead of the first one in the same table the PQ will give the wrong message that headers do not match. My target is not to create a new PQ each time I need to update input data. Target is to have a PQ that I refresh after inserting new data to the table and it updates output table automatically. 

I hope it is more clear now. 

BR//Larissa

camargos88
Community Champion
Community Champion

@L70F ,

 

Have you tried switching the values.

There no reference to the headers beside "Row Labels", once you have "Row Labels" as column everything else will be unpivoted.

 

Try it switching the values on the 2 table of the pbix provided.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Hi,

Thank you for your reply. 

I don't work in Power BI PQ and don't know how to use your pbix file. 

Could you please share your codes so I can use it in  Excel Power Query. Sorry for additional trouble. 

BR//Larissa

v-yingjl
Community Support
Community Support

Hi @L70F ,

For example 1, here is the power query code in excel:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Row Labels", Int64.Type}, {"1", type number}, {"2", type number}, {"3", type number}, {"4", type number}, {"5", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Row Labels"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Qty"}, {"Value", "Price"}})
in
    #"Renamed Columns"

 e1.png

example 2 is simliar with example 1.

Attached the sample excel file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

Please find the step below, I run the same in EXCEL POWER QUERY, same you can run in POWER BI POWER QUERY

 

1. Load data into power query

2. Make sure QTY in the header (as below image)

3. Select the first column

4. Go to UNPIVOT COLUMN > Unpivot Other Column

5. Done, change the Column Header as per your requirement

 

pijush1.jpg

 

Now see the result

pijush2.jpg

 

Also if you want to advance the crosstab matrix table to a simple data table, please find a tutorial for referance -myaccountingtricks.com/2020/06/convert-crosstab-matrix-excel-list-data-table-unpivot.html, may it will help you.

 

If you find this is the solution, please mark as the solution and give kudos

 

Thanks
Pijush

Thank you Pijush for your link. I have watched it and solved my problem. 

BR//Larissa

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors