Rows to Columns

hasanlianar

New Member
Joined
Jul 21, 2011
Messages
43
Hi,

Is it possible to convert rows to columns using Power Query, as in the example below:

FROM:

CodeType
123a
123b
123c
456d
456e
789f
789g

<tbody>
</tbody>

TO:

CodeType1Type2Type3
123abc
456de
789fg

<tbody>
</tbody>


Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
There are probably lots of ways to do it, but I don't think any are that obvious. Here's one:

First make sure your table is sorted on the Code column. Add an index column to your table in PQ, starting at 0, then group that table by Code calculating the Min of the new index column. Save that as a connection only query.
Load your table into PQ again and merge it into the provious query using the Code field. Expand the table produced for each row, keeping just the Min value.
Now add a new index field, starting at 1 this time, and then create a calculated column subtracting the Min value from the index field. That should give you effectively a counter for each code, starting at 1.
You can then pivot the new counter field, using Type as the value field and specifying 'Don't aggregate' in the advanced options.
 
Upvote 0
Thank you for the solution. I thought conversion can be achieved with just a few clicks in PQ.
I followed your steps, though I could not end up with the desired result/
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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