How to Rotate Rows to Columns with Large Data Set

Saacko

New Member
Joined
Feb 1, 2024
Messages
12
Office Version
  1. 2021
Platform
  1. Windows
Hello everyone,

I have a fairly large amount of data that in columns, but I would like to convert them to rows. I know simply transposing seems like the obvious answer, but it does not work for this data set. Please see below:

Buy On Paper - RevD.xlsx
ABCDEFGHI
20Packages and DurationsProject Set-UpMaterial Contract 5Material Contract 4Material Contract 3Material Contract 2Material Contract 1Short Form Material Contractthese go for hundred of columns….
21Activity N, in hours0200280380520640720
22Activity I, in hours100340320300280260260
23Activity Q, in hours100280260240220200200
24Activity D, in hours029201920160014401280960
25
26How I want it:
27Project Set-Up -Activity N, in hours0
28Project Set-Up -Activity I, in hours100
29Project Set-Up -Activity Q, in hours100
30Project Set-Up -Activity D, in hours0
31Material Contract 5 -Activity N, in hours200
32Material Contract 5 -Activity I, in hours340
33Material Contract 5 -Activity Q, in hours280
34Material Contract 5 -Activity D, in hours2920
35Material Contract 4 -Activity N, in hours280
36Material Contract 4 -Activity I, in hours320
37Material Contract 4 -Activity Q, in hours260
38Material Contract 4 -Activity D, in hours1920
39Material Contract 3 -Activity N, in hours380
40Material Contract 3 -Activity I, in hours300
41Material Contract 3 -Activity Q, in hours240
42Material Contract 3 -Activity D, in hours1600
43Material Contract 2 -Activity N, in hours520
44Material Contract 2 -Activity I, in hours280
45Material Contract 2 -Activity Q, in hours220
46Material Contract 2 -Activity D, in hours1440
47etc.
48etc.
49etc.
50etc.
Transposed Test Data


So first, I am trying to have my Package names Concat with my Activity names. Then, I need those names to match up with my durations. It's important that my activities remain in the order of N, then I, then Q, and then D. I am able to get all my names to Concat in a row format and then I transpose them vertically. I then cut and paste the "I" sections under the "N", then "Q" under the "I", and then "D" under the "Q. "That works well, but I can't seem to sort them to get them in the right order after that. I want the packages in alphabetical order just like above and then sorted by N,I,Q,D. Once I get my names in the right order as shown above, the next challenge is getting the durations to match up I have tried lookups and transposing but nothing really works. I need my data in one column as shown in the spreadsheet.

Recap:

1. I need help taking this data and making it vertical into one column.
2. I can get my names to concat in a row format and then transpose to vertical, but I can't sort them in the right order. I want alphabetical order, and then by N,I,Q,D.
3. Once I get my names in the right order, I need to get the durations to match up.

Please let me know if this will be possible to achieve, thank you all.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Packages and Durations"}, "Attribute", "Value"),
    #"Sorted Rows" = Table.Sort(#"Unpivoted Other Columns",{{"Attribute", Order.Ascending}}),
    #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Packages and Durations"})
in
    #"Removed Columns"

Book5
DE
8AttributeValue
9Material Contract 11280
10Material Contract 1640
11Material Contract 1200
12Material Contract 1260
13Material Contract 2280
14Material Contract 2220
15Material Contract 21440
16Material Contract 2520
17Material Contract 3240
18Material Contract 31600
19Material Contract 3300
20Material Contract 3380
21Material Contract 4280
22Material Contract 4260
23Material Contract 4320
24Material Contract 41920
25Material Contract 5200
26Material Contract 52920
27Material Contract 5340
28Material Contract 5280
29Project Set-Up0
30Project Set-Up100
31Project Set-Up100
32Project Set-Up0
33Short Form Material Contract960
34Short Form Material Contract720
35Short Form Material Contract260
36Short Form Material Contract200
Sheet1
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Packages and Durations"}, "Attribute", "Value"),
    #"Sorted Rows" = Table.Sort(#"Unpivoted Other Columns",{{"Attribute", Order.Ascending}}),
    #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Packages and Durations"})
in
    #"Removed Columns"

Book5
DE
8AttributeValue
9Material Contract 11280
10Material Contract 1640
11Material Contract 1200
12Material Contract 1260
13Material Contract 2280
14Material Contract 2220
15Material Contract 21440
16Material Contract 2520
17Material Contract 3240
18Material Contract 31600
19Material Contract 3300
20Material Contract 3380
21Material Contract 4280
22Material Contract 4260
23Material Contract 4320
24Material Contract 41920
25Material Contract 5200
26Material Contract 52920
27Material Contract 5340
28Material Contract 5280
29Project Set-Up0
30Project Set-Up100
31Project Set-Up100
32Project Set-Up0
33Short Form Material Contract960
34Short Form Material Contract720
35Short Form Material Contract260
36Short Form Material Contract200
Sheet1
Thank you for setting this code up for me, I will admit I am fairly new to Power Queries. I am trying to enter it, but it keeps giving me syntax errors. Here's what I see when I try and enter the formula:
1707498583389.png

There is just a ton of columns and I am not sure where I should paste your formula. Please excuse me if this is dumb question, like I said I am new to this.

Do you think you could help me with how to enter it?

I would greatly appreciate and am already thankful for the help you have provided.

Thanks,
 
Upvote 0
this should help

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
this should help

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
Thank you for sending this, I was able to watch a couple videos and figure out how to run the code you gave me. However, it's still not lining up my data quite the way I want it to. The code got my name and duration columns to become vertical. But I don't know which activity is which and which duration goes with each activity. It would seem I can either get my names to show up correctly or I can get the durations but not know which activity they are tied to.
1707759040813.png

1707759089932.png


Here is how my data actually looks and the highlighted is how I want to have it:

Buy On Paper - RevD - Copy 2.xlsm
ABCDEFGHI
1Packages and DurationsProject Set-UpColumn3Column4Column5Material Contract 5Column7Column8Column9
2NTP to IFR, HoursProject Set-Up - NTP to IFR, Hours1. PSU - Project0FSMaterial Contract 5 - NTP to IFR, Hours1. MC5 - Materia200FS
3IFR to Quote (Proposal Received), HoursProject Set-Up - IFR to Quote (Proposal Received), Hours2. PSU - Project100FSMaterial Contract 5 - IFR to Quote (Proposal Received), Hours2. MC5 - Materia340FS
4Quote (Proposal Received) to Award, HoursProject Set-Up - Quote (Proposal Received) to Award, Hours3. PSU - Project100FSMaterial Contract 5 - Quote (Proposal Received) to Award, Hours3. MC5 - Materia280FS
5Award to Delivery or Completion, HoursProject Set-Up - Award to Delivery or Completion, Hours4. PSU - Project0FSMaterial Contract 5 - Award to Delivery or Completion, Hours4. MC5 - Materia2920FS
6
7
8
9Package nameDurationLogicAbbreviation
10Project Set-Up - NTP to IFR, Hours0FS1. PSU - Project
11Project Set-Up - IFR to Quote (Proposal Received), Hours100FS2. PSU - Project
12Project Set-Up - Quote (Proposal Received) to Award, Hours100FS3. PSU - Project
13Project Set-Up - Award to Delivery or Completion, Hours0FS4. PSU - Project
14Material Contract 5 - NTP to IFR, Hours200FS1. MC5 - Materia
15Material Contract 5 - IFR to Quote (Proposal Received), Hours340FS2. MC5 - Materia
16Material Contract 5 - Quote (Proposal Received) to Award, Hours280FS3. MC5 - Materia
17Material Contract 5 - Award to Delivery or Completion, Hours2920FS4. MC5 - Materia
Table14


Please keep in mind the only column labels are the names of the packages. If you want me to have columns names for each column to tie them to the package, I would have to do some extra work to make it look like this:

Buy On Paper - RevD - Copy 2.xlsm
ABCDEFGHI
19Packages and DurationsProject Set-UpProject Set-UpProject Set-UpProject Set-UpMaterial Contract 5Material Contract 5Material Contract 5Material Contract 5
20NTP to IFR, HoursProject Set-Up - NTP to IFR, Hours1. PSU - Project0FSMaterial Contract 5 - NTP to IFR, Hours1. MC5 - Materia200FS
21IFR to Quote (Proposal Received), HoursProject Set-Up - IFR to Quote (Proposal Received), Hours2. PSU - Project100FSMaterial Contract 5 - IFR to Quote (Proposal Received), Hours2. MC5 - Materia340FS
22Quote (Proposal Received) to Award, HoursProject Set-Up - Quote (Proposal Received) to Award, Hours3. PSU - Project100FSMaterial Contract 5 - Quote (Proposal Received) to Award, Hours3. MC5 - Materia280FS
23Award to Delivery or Completion, HoursProject Set-Up - Award to Delivery or Completion, Hours4. PSU - Project0FSMaterial Contract 5 - Award to Delivery or Completion, Hours4. MC5 - Materia2920FS
Table14


However, if I do that, my data doesn't come out right either:
1707762432232.png


I don't know which activity those durations are tied to.


I hope there is a way you can help me with this, I'm sorry if this isn't making any sense.

I really appreciate all the help you have given me so far.

- Scout
 
Upvote 0
Based upon your latest proposed solution
Three steps
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Packages and Durations", "Project Set-Up", "Column3", "Column4", "Column5"})
in
    #"Removed Other Columns"

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Material Contract 5", "Column7", "Column8", "Column9"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Material Contract 5", "Project Set-Up"}, {"Column7", "Column3"}, {"Column8", "Column4"}, {"Column9", "Column5"}})
in
    #"Renamed Columns"

Append the two queries as new

Power Query:
let
    Source = Table.Combine({Table1, #"Table1 (2)"}),
    #"Removed Columns" = Table.RemoveColumns(Source,{"Packages and Durations"})
in
    #"Removed Columns"
Book2
ABCD
1Project Set-UpColumn3Column4Column5
2Project Set-Up - NTP to IFR, Hours1. PSU - Project0FS
3Project Set-Up - IFR to Quote (Proposal Received), Hours2. PSU - Project100FS
4Project Set-Up - Quote (Proposal Received) to Award, Hours3. PSU - Project100FS
5Project Set-Up - Award to Delivery or Completion, Hours4. PSU - Project0FS
6Material Contract 5 - NTP to IFR, Hours1. MC5 - Materia200FS
7Material Contract 5 - IFR to Quote (Proposal Received), Hours2. MC5 - Materia340FS
8Material Contract 5 - Quote (Proposal Received) to Award, Hours3. MC5 - Materia280FS
9Material Contract 5 - Award to Delivery or Completion, Hours4. MC5 - Materia2920FS
Append1
 
Upvote 0
If VBA is an option you'd consider, please try the following on a copy of your workbook. Assumes your layout is exactly as you show in post #5, and that the sheet is called Table14, the following code:

VBA Code:
Option Explicit
Sub Saacko()
    Dim ws As Worksheet, LCol As Long
    Set ws = Worksheets("Table14")          '<-- *** Change sheet name to suit ***
    LCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
    Dim arrIn, arrOut, i As Long, j As Long, k As Long, m As Long
    arrIn = ws.Range(ws.Cells(2, 2), ws.Cells(5, LCol))
    ReDim arrOut(1 To LCol - 1, 1 To 4)
    
    j = 1: k = 1
    For i = 1 To UBound(arrOut, 1)
        arrOut(i, 1) = arrIn(j, k)
        arrOut(i, 2) = arrIn(j, k + 2)
        arrOut(i, 3) = arrIn(j, k + 3)
        arrOut(i, 4) = arrIn(j, k + 1)
        m = m + 1
        If m = 4 Then
            k = k + 4
            m = 0
        End If
        If j = 4 Then j = 1 Else j = j + 1
    Next i
    ws.Range("A10").Resize(UBound(arrOut, 1), 4).Value = arrOut
End Sub

Turns this:
move data.xlsm
ABCDEFGHI
1Packages and DurationsProject Set-UpColumn3Column4Column5Material Contract 5Column7Column8Column9
2NTP to IFR, HoursProject Set-Up - NTP to IFR, Hours1. PSU - Project0FSMaterial Contract 5 - NTP to IFR, Hours1. MC5 - Materia200FS
3IFR to Quote (Proposal Received), HoursProject Set-Up - IFR to Quote (Proposal Received), Hours2. PSU - Project100FSMaterial Contract 5 - IFR to Quote (Proposal Received), Hours2. MC5 - Materia340FS
4Quote (Proposal Received) to Award, HoursProject Set-Up - Quote (Proposal Received) to Award, Hours3. PSU - Project100FSMaterial Contract 5 - Quote (Proposal Received) to Award, Hours3. MC5 - Materia280FS
5Award to Delivery or Completion, HoursProject Set-Up - Award to Delivery or Completion, Hours4. PSU - Project0FSMaterial Contract 5 - Award to Delivery or Completion, Hours4. MC5 - Materia2920FS
6
7
8
9Package nameDurationLogicAbbreviation
10
Table14


Into this:
move data.xlsm
ABCDEFGHI
1Packages and DurationsProject Set-UpColumn3Column4Column5Material Contract 5Column7Column8Column9
2NTP to IFR, HoursProject Set-Up - NTP to IFR, Hours1. PSU - Project0FSMaterial Contract 5 - NTP to IFR, Hours1. MC5 - Materia200FS
3IFR to Quote (Proposal Received), HoursProject Set-Up - IFR to Quote (Proposal Received), Hours2. PSU - Project100FSMaterial Contract 5 - IFR to Quote (Proposal Received), Hours2. MC5 - Materia340FS
4Quote (Proposal Received) to Award, HoursProject Set-Up - Quote (Proposal Received) to Award, Hours3. PSU - Project100FSMaterial Contract 5 - Quote (Proposal Received) to Award, Hours3. MC5 - Materia280FS
5Award to Delivery or Completion, HoursProject Set-Up - Award to Delivery or Completion, Hours4. PSU - Project0FSMaterial Contract 5 - Award to Delivery or Completion, Hours4. MC5 - Materia2920FS
6
7
8
9Package nameDurationLogicAbbreviation
10Project Set-Up - NTP to IFR, Hours0FS1. PSU - Project
11Project Set-Up - IFR to Quote (Proposal Received), Hours100FS2. PSU - Project
12Project Set-Up - Quote (Proposal Received) to Award, Hours100FS3. PSU - Project
13Project Set-Up - Award to Delivery or Completion, Hours0FS4. PSU - Project
14Material Contract 5 - NTP to IFR, Hours200FS1. MC5 - Materia
15Material Contract 5 - IFR to Quote (Proposal Received), Hours340FS2. MC5 - Materia
16Material Contract 5 - Quote (Proposal Received) to Award, Hours280FS3. MC5 - Materia
17Material Contract 5 - Award to Delivery or Completion, Hours2920FS4. MC5 - Materia
18
Table14
 
Upvote 1
Solution

Kevin,
I tried this and it worked on all of my data. It is perfect! I can't thank you enough for helping me with this. I have been trying to find this answer for weeks now and the VBA was much simpler than the power query.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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