Access to arrange the data from vertical to horizontal

dhen21dx

Board Regular
Joined
May 10, 2013
Messages
166
Hello,

I need advise on how can i do the sets of data from vertical to horizontal. here is the example below.

IDCatergoryDescr
11111​
Sales IDUUAD
11111​
OriginUS
11111​
PurVar
5​
11111​
DecrDelta
22222​
OriginTH
22222​
PurVar
7​
33333​
Sales IDUUAT
33333​
OriginDE
33333​
DecrDelta_XR


Result:

IDSales IDPurVarOriginDecr
11111​
UUAD
5​
USDelta
22222​
 
7​
TH 
33333​
UUAT DEDelta_XR
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
For this you can use a crosstab query. But this will only give reliable results when there is only one entry for each ID/Category combination!

Also, this is rather slow within Access. If you intend to export this to Excel at some point, you are really better of using Excel to do this!

Anyway: assume your data is listed in Table1:

SQL:
TRANSFORM Max(Table1.Descr) AS MaxOfDescr
SELECT Table1.ID
FROM Table1
GROUP BY Table1.ID
PIVOT Table1.Catergory;
 
Upvote 0
Solution
You could also bring the data from Access into Power Query Editor and Pivot the data.
 
Upvote 0
Power Query Editor is within excel right?, can it be that i have a fixed category. I do have sometimes one category that is missing and i still do need to reflect it even though blanks
 
Upvote 0
TRANSFORM Max(Table1.Descr) AS MaxOfDescr SELECT Table1.ID FROM Table1 GROUP BY Table1.ID PIVOT Table1.Catergory;
I tried that. The result leaves out a Descr value for 1111 (shown in sample as Delta) and I cannot figure out why. Any attempt I've made results in an error or this:
Query7 Query7

IDSales IDPurVarOriginDecr
1111​
UUAD5US
2222​
THDelta
3333​
UUAT7DEDelta_XR
2222 has no Delta value in the sample; 3333 has no PurVar of 7. When I copied table from forum I lost the ID values and had to type them in myself. I've left out digits for the IDs but that should not matter. I believe there are other errors as well, which no doubt are all related to the same cause.
 
Upvote 0
I tried that. The result leaves out a Descr value for 1111 (shown in sample as Delta) and I cannot figure out why. Any attempt I've made results in an error or this:
Query7 ...

try again,
I am not familiar with these types of queries so I wanted to try it to learn
I went to access and did Create / Table
and pasted in the data of all 3 columns at once and then I edited the field names from F1, F2, F3 to their proper values
I ran the query and it worked as expected

"2222 has no Delta value in the sample; 3333 has no PurVar of 7"
the query put in an empty string (or maybe a null) for the missing values
 
Upvote 0
Not sure why I'd try the same thing again and expect a different result. The only thing different that I can see is that I started with a spreadsheet that I imported and saved with a table name of dhen21dx so the actual sql is
SQL:
TRANSFORM Max(dhen21dx.Descr) AS MaxOfDescr
SELECT dhen21dx.ID
FROM dhen21dx
GROUP BY dhen21dx.ID
PIVOT dhen21dx.Catergory;
My comment about no data in a record refers to the sample data in post 1, not the query results. If you review my result against the sample data I think you'll see what I mean (hopefully). I ended up with transformed data in a record where there should not be any. Gotta run for today.
 
Upvote 0
If you bring your data to PQ with this Mcode. You will of course need to change the source from the Current Workbook to your Access Table or Query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Catergory", type text}, {"Descr", type any}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Catergory]), "Catergory", "Descr")
in
    #"Pivoted Column"

the result looks like this:

Book3
ABCDE
1IDSales IDOriginPurVarDecr
211111UUADUS5Delta
322222TH7
433333UUATDEDelta_XR
Table1
 
Upvote 0

Forum statistics

Threads
1,221,534
Messages
6,160,385
Members
451,645
Latest member
hglymph

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