Transform data - Is it transpose??

keiranwyllie

New Member
Joined
May 12, 2017
Messages
47
Hi everyone, hoping someone can provide some guidance.

Essentially I have rows of data that contain dates of various course completions against staff (one staff member per row). I want to transform that data into columns but transpose doesn't seem to be the most appropriate way I can do this. I've looked at power query too and can't really reach my end state.

Below is an example of the original data and then the way I need it to look. You can see that I need to fill the IDs and Names down the column provided the Cse/Dates are associated with that staff member.

Any help is greatly appreciated.

SurnameFirstIDPhoneCompanyCse 1Cse 2Cse 3Cse 4Cse 5
BloggsJoe12345111222A11/07/202112/03/20211/04/202129/07/20218/02/2021
SmithBob12435112233A128/02/20213/03/202120/05/202116/02/202130/06/2021


IDNameCse NameDate
12345Bloggs,JoeCse 11/07/2021
12345Bloggs,JoeCse 212/03/2021
12345Bloggs,JoeCse 31/04/2021
12345Bloggs,JoeCse 429/07/2021
12345Bloggs,JoeCse 58/02/2021
12435Smith,BobCse 128/02/2021
12435Smith,BobCse 23/03/2021
12435Smith,BobCse 320/05/2021
12435Smith,BobCse 416/02/2021
12435Smith,BobCse 530/06/2021
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You're manipulating rather than simply transposing, so something like this does the job:
VBA Code:
Sub transposeplus()

Sheet1.Activate
Dim r() As Variant
r = Sheet1.Range("A1").CurrentRegion

Sheet2.Activate
Cells(1, 1) = "ID": Cells(1, 2) = "Name": Cells(1, 3) = "Cse Name": Cells(1, 4) = "Date"

Dim n As Integer
Dim x As Integer
For n = 2 To UBound(r)
    For x = 0 To 4
        Cells(n + x + ((n - 2) * 4), 1) = r(n, 3)
        Cells(n + x + ((n - 2) * 4), 2) = r(n, 1) + "," + r(n, 2)
        Cells(n + x + ((n - 2) * 4), 3) = "Cse " + Trim(Str(x + 1))
        Cells(n + x + ((n - 2) * 4), 4) = r(n, 6 + x)
    Next x
Next n
End Sub
Where your source data is in Sheet1 and you have a blank Sheet2.
 
Upvote 0
If you want to use Power Query then
  • Data > From Table/Range
  • Select the columns from Surname to Company
  • Tranform > Unpivot Columns > Unpivot Other Columns
 
Upvote 0
If you want to use Power Query then
  • Data > From Table/Range
  • Select the columns from Surname to Company
  • Tranform > Unpivot Columns > Unpivot Other Columns
Man that Power Query is so simple I now feel like an idiot. It looks the goods and works perfectly on my sample spreadsheet. I'll test on on the real thing and let you know.
 
Upvote 0
Thanks for the update. Unpivoting is one of the things it is really good at.
There are some tricks though. It is like recording a macro with certain steps hard coding column names.

In this case it is likely that the second step was Changed Type, this will hard code you Case 1 - 5 and this might later change to being more or less case columns.
Delete that Changed Type step.
After you unpivot, it doesn't matter how may cases you have, you will always have the same number of columns.
So apply a Changed Type step AFTER the unpivot.
  • Select anywhere in the grid.
  • Transform > Detect data type
  • Then review the data types to make sure you are happy.
    I then added a change to make the date just the date (not date & time)
    If a Change Column Type box appears > select Replace Current
    (this merges this Changed Type step with the previous one so you only have one Changed Type step)
 
Upvote 0
D
If you want to use Power Query then
  • Data > From Table/Range
  • Select the columns from Surname to Company
  • Tranform > Unpivot Columns > Unpivot Other Columns
Dang, that's cool. I'm very familiar with Excel and VBA, but I don't know much about Power Query since my work doesn't have access to it. Guess I gotta start learning.
 
Upvote 0
D

Dang, that's cool. I'm very familiar with Excel and VBA, but I don't know much about Power Query since my work doesn't have access to it. Guess I gotta start learning.
Hear hear. I'd used these for API data scraping but hadn't looked into it further.
 
Upvote 0
So to go one step further, if I have training codes allocated to courses plus expiry dates, can I also use power query to manipulate it in the same way?

From this:
data transform.xlsx
ABCDEFGHIJKLMNOPQRST
1SurnameFirstIDPhoneCompanyTng Code1Cse 1Cse 1 ExpTng Code2Cse 2Cse 2 ExpTng Code3Cse 3Cse 3 ExpTng Code4Cse 4Cse 4 ExpTng Code5Cse 5Cse 6
2BloggsJoe12345111222A1Cse1 Code1/07/20211/07/2022Cse2 Code12/03/20211/07/2022Cse3 Code1/04/20211/07/2022Cse4 Code29/07/20211/07/2022Cse5 Code8/02/202129/07/2021
3SmithBob12435112233A1Cse1 Code28/02/202128/02/2022Cse2 Code3/03/202128/02/2022Cse3 Code20/05/202128/02/2022Cse4 Code16/02/202128/02/2022Cse5 Code30/06/202130/07/2021
4HoldenRoger54321221133A1Cse1 Code20/05/202120/05/2022Cse2 Code16/02/202120/05/2022Cse3 Code28/02/202120/05/2022Cse4 Code30/06/202120/05/2022Cse5 Code3/03/202131/07/2021
Sheet1


To This:
data transform.xlsx
ABCDEFGH
12IDMergedPhoneCompanyTng CodeCseCompletedExpires
1312345Bloggs,Joe111222A1Cse1 CodeCse 11/07/20211/07/2022
1412345Bloggs,Joe111222A1Cse2 CodeCse 212/03/202112/03/2022
1512345Bloggs,Joe111222A1Cse3 CodeCse 31/04/20211/04/2022
1612345Bloggs,Joe111222A1Cse4 CodeCse 429/07/202129/07/2022
1712345Bloggs,Joe111222A1Cse5 CodeCse 58/02/20218/02/2022
1812435Smith,Bob112233A1Cse1 CodeCse 128/02/202128/02/2022
1912435Smith,Bob112233A1Cse2 CodeCse 23/03/20213/03/2022
2012435Smith,Bob112233A1Cse3 CodeCse 320/05/202120/05/2022
2112435Smith,Bob112233A1Cse4 CodeCse 416/02/202116/02/2022
2212435Smith,Bob112233A1Cse5 CodeCse 530/06/202130/06/2022
2354321Holden,Roger221133A1Cse1 CodeCse 120/05/202120/05/2022
2454321Holden,Roger221133A1Cse2 CodeCse 216/02/202116/02/2022
2554321Holden,Roger221133A1Cse3 CodeCse 328/02/202128/02/2022
2654321Holden,Roger221133A1Cse4 CodeCse 430/06/202130/06/2022
2754321Holden,Roger221133A1Cse5 CodeCse 53/03/20213/03/2022
Sheet1
 
Upvote 0
Can I assume that Tng Code1 relates to Cse 1 (both 1)
I also assume that Cse1 Code under Tng Code1 is just an example and that it might not be 1 or the exercise seems a bit pointless.

In the headings are you able to make them consistent ?
eg add a space before the number in Tng Code1 same as in "Cse 1"
 
Upvote 0
Can I assume that Tng Code1 relates to Cse 1 (both 1)
I also assume that Cse1 Code under Tng Code1 is just an example and that it might not be 1 or the exercise seems a bit pointless.

In the headings are you able to make them consistent ?
eg add a space before the number in Tng Code1 same as in "Cse 1"
It does. I've just tried to use really basic headings in my example to keep it simple (well hopefully). In my real Data, it's 'Proficiency Code (Cse1)' and 'Cse1'. Basically, the 1's belong together, 2's together and so on (they're different codes for each course).

And yeah, 'Tng Code1' can easily be 'Tng Code 1'.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
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