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

Product Code Product NameP01P02P03
AA01LundryTomTomEric
AA02PrestoBobTomBob
AA03ParsaEricTomEric


Product Code Product NamePeriod
AA01LundryTom
AA01LundryTom
AA01LundryEric
AA02PrestoBob
AA02PrestoTom
AA02PrestoBob
AA03ParsaEric
AA03ParsaTom
AA03ParsaEric
<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> </tbody>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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