Crosstab - Making column data to row data

khexcel

Board Regular
Joined
Apr 8, 2004
Messages
54
I have unique date like this (2 columns type and class):
Type Class
A 1
A 2
A 3
B 1
C 1
C 2
D 1

And I want to display like this (multiple columns, 1 with type and others with class):

Type Class1 Class2 Class3 Class4...
A 1 2 3
B 1
C 1 2
D 1

I do not know the number of classes but want access to automatically name the column. It's like a pivot table but instead of summarizing the class data, I want to display the actually value (class). Can someone help? :rolleyes:
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
First create this query:

SELECT Sheet1.Type, Sheet1.Class, "Class" & [Class] AS ClassType
FROM Sheet1;

Replacing Sheet1 with your table name.

Then create this crosstab query:

TRANSFORM Max(Query1.Class) AS MaxOfClass
SELECT Query1.Type
FROM Query1
GROUP BY Query1.Type
PIVOT Query1.ClassType;

I tested it using your data and it seems to do what you want.
 
Upvote 0

Forum statistics

Threads
1,221,828
Messages
6,162,215
Members
451,752
Latest member
freddocp

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