Transpose Table

brendanolear

Active Member
Joined
Apr 26, 2008
Messages
366
I have a basic table I wish to transpose but can't seem to do so in access.
I use the normalization method excel, but can't see how it can be achieved in access.

Current Table at top and outcome I seek is below

[TABLE="width: 335"]
<colgroup><col width="90" style="width: 67pt; mso-width-source: userset; mso-width-alt: 3185;"> <col width="166" style="width: 124pt; mso-width-source: userset; mso-width-alt: 5888;"> <col width="64" style="width: 48pt;" span="3"> <tbody>[TR]
[TD="width: 90, bgcolor: transparent"]Product Code [/TD]
[TD="width: 166, bgcolor: transparent"]Product Name[/TD]
[TD="width: 64, bgcolor: transparent"]P01[/TD]
[TD="width: 64, bgcolor: transparent"]P02[/TD]
[TD="width: 64, bgcolor: transparent"]P03[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA01[/TD]
[TD="bgcolor: transparent"]Lundry[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"]Eric[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA02[/TD]
[TD="bgcolor: transparent"]Presto[/TD]
[TD="bgcolor: transparent"]Bob[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"]Bob[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA03[/TD]
[TD="bgcolor: transparent"]Parsa[/TD]
[TD="bgcolor: transparent"]Eric[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"]Eric[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]

[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]Product Code [/TD]
[TD="bgcolor: transparent"]Product Name[/TD]
[TD="bgcolor: transparent"]Period[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA01[/TD]
[TD="bgcolor: transparent"]Lundry[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA01[/TD]
[TD="bgcolor: transparent"]Lundry[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA01[/TD]
[TD="bgcolor: transparent"]Lundry[/TD]
[TD="bgcolor: transparent"]Eric[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA02[/TD]
[TD="bgcolor: transparent"]Presto[/TD]
[TD="bgcolor: transparent"]Bob[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA02[/TD]
[TD="bgcolor: transparent"]Presto[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA02[/TD]
[TD="bgcolor: transparent"]Presto[/TD]
[TD="bgcolor: transparent"]Bob[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA03[/TD]
[TD="bgcolor: transparent"]Parsa[/TD]
[TD="bgcolor: transparent"]Eric[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA03[/TD]
[TD="bgcolor: transparent"]Parsa[/TD]
[TD="bgcolor: transparent"]Tom[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]AA03[/TD]
[TD="bgcolor: transparent"]Parsa[/TD]
[TD="bgcolor: transparent"]Eric[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]
 

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.
You can create a "UNION ALL" query in Access to do this.
So, if your Table was named "Table1", the SQL code for the query would look like:
Code:
SELECT Table1.[Product Code], Table1.[Product Name], Table1.[P01] AS Period
FROM Table1
UNION ALL
SELECT Table1.[Product Code], Table1.[Product Name], Table1.[P02] AS Period
FROM Table1
UNION ALL
SELECT Table1.[Product Code], Table1.[Product Name], Table1.[P03] AS Period
FROM Table1
ORDER BY Table1.[Product Code];
 
Upvote 0
I've missed out a critical requirement. I would also like to see a 4th column, as per example above, P01 would be present to show Month etc. Is that possible in a select query?
 
Last edited:
Upvote 0
I've missed out a critical requirement. I would also like to see a 4th column, as per example above, P01 would be present in first 3 rows, P02 in rows 4 to 6 etc. Is that possible in a select query?
I am not sure I follow what you are saying your structure is. If there are really 4 "P0" columns, just continue on with another "UNION ALL" block in the SQL code.
If that is not what you mean, please show examples of data and expected results like you did in your original post.
 
Upvote 0
Sorry Joe4 - didn't explain properly. I've resolved. I just needed to add a "P01" within your code at Period P01 to record a flag in the fourth column. Copy that through "P02" etc. Thanks again.
 
Upvote 0
Ah yes, I see now.
Yes, you would just hard-code in "P01", "P02", etc at the end of the SELECT lines in each block.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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