Excel pivot table or pivot in Power Query to do this?

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
437
Office Version
  1. 365
Platform
  1. Windows
Hi I'm trying to create a pivot table in structure shown in row 17 downwards (i.e. counting the number of users by response, but need to break it down by category and question.

I'm getting stuck because I can't work out how to arrange the pivot table to do that. I guess I need to transform my data first, but would appreciate some guidance on how to do that. Can anybody help?



Book1
BCDEFGHIJKLMNOPQ
5Source Data
6
7UserQ1Q1 CategoryAnswer 1Q2Q2 CategoryAnswer 2Q3Q3 CategoryAnswer 3Q4Q4 CategoryAnswer 4Q5Q5 CategoryAnswer 5
8User 1Age?PhysicalHighHeight?PhysicalLowShoe Size?PhysicalMediumPreferred food?PreferenceHighPreferred Colour?PreferenceHigh
9User 2Age?PhysicalHighHeight?PhysicalHighShoe Size?PhysicalMediumPreferred food?PreferenceLowPreferred Colour?PreferenceLow
10User 3Age?PhysicalMediumHeight?PhysicalHighShoe Size?PhysicalMediumPreferred food?PreferenceLowPreferred Colour?PreferenceLow
11User 4Age?PhysicalMediumHeight?PhysicalHighShoe Size?PhysicalHighPreferred food?PreferenceLowPreferred Colour?PreferenceMedium
12User 5Age?PhysicalMediumHeight?PhysicalHighShoe Size?PhysicalHighPreferred food?PreferenceMediumPreferred Colour?PreferenceMedium
13User 6Age?PhysicalLowHeight?PhysicalMediumShoe Size?PhysicalLowPreferred food?PreferenceLowPreferred Colour?PreferenceMedium
14
15
16Desired Output - ideally pivot table:
17HighMediumLow
18Physical
19Age?231
20Height?411
21Shoe Size?231
22Preference
23Preferred food?114
24Preferred Colour?132
Sheet2
Cell Formulas
RangeFormula
C19:E19C19=COUNTIFS(Data_Table[Answer 1],C$17)
C20:E20C20=COUNTIFS(Data_Table[Answer 2],C$17)
C21:E21C21=COUNTIFS(Data_Table[Answer 3],C$17)
C23:E23C23=COUNTIFS(Data_Table[Answer 4],C$17)
C24:E24C24=COUNTIFS(Data_Table[Answer 5],C$17)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Is there a specific reason why you need a pivot table?
 
Upvote 0
If the answer is yes, you would need to rearrange your data, like below:
Book1.xlsx
ABCDEFGHIJK
1
2UserQuestionCategoryAnswerCount of Answer
3User 1Age?PhysicalHighRow LabelsHighLowMedium
4User 2Age?PhysicalHighPhysical837
5User 3Age?PhysicalMediumAge?213
6User 4Age?PhysicalMediumHeight?411
7User 5Age?PhysicalMediumShoe Size?213
8User 6Age?PhysicalLowPreference264
9User 1Height?PhysicalLowPreferred Colour?123
10User 2Height?PhysicalHighPreferred food?141
11User 3Height?PhysicalHigh
12User 4Height?PhysicalHigh
13User 5Height?PhysicalHigh
14User 6Height?PhysicalMedium
15User 1Shoe Size?PhysicalMedium
16User 2Shoe Size?PhysicalMedium
17User 3Shoe Size?PhysicalMedium
18User 4Shoe Size?PhysicalHigh
19User 5Shoe Size?PhysicalHigh
20User 6Shoe Size?PhysicalLow
21User 1Preferred food?PreferenceHigh
22User 2Preferred food?PreferenceLow
23User 3Preferred food?PreferenceLow
24User 4Preferred food?PreferenceLow
25User 5Preferred food?PreferenceMedium
26User 6Preferred food?PreferenceLow
27User 1Preferred Colour?PreferenceHigh
28User 2Preferred Colour?PreferenceLow
29User 3Preferred Colour?PreferenceLow
30User 4Preferred Colour?PreferenceMedium
31User 5Preferred Colour?PreferenceMedium
32User 6Preferred Colour?PreferenceMedium
Sheet3
 
Upvote 0
Thanks, yes reason for pivot table as a final result is I'd like to use slicers with it.

Now I need to try to work out the power query to rearrange the data....
 
Upvote 0
Is VSTACK an option? Or is it that you require it to be transformed from an external file?
Book1.xlsx
KLMNOPQRSTUVWXYZAA
1
2Age?PhysicalHighHeight?PhysicalLowShoe Size?PhysicalMediumPreferred food?PreferenceHighPreferred Colour?PreferenceHigh
3Age?PhysicalHighHeight?PhysicalHighShoe Size?PhysicalMediumPreferred food?PreferenceLowPreferred Colour?PreferenceLow
4Age?PhysicalMediumHeight?PhysicalHighShoe Size?PhysicalMediumPreferred food?PreferenceLowPreferred Colour?PreferenceLow
5Age?PhysicalMediumHeight?PhysicalHighShoe Size?PhysicalHighPreferred food?PreferenceLowPreferred Colour?PreferenceMedium
6Age?PhysicalMediumHeight?PhysicalHighShoe Size?PhysicalHighPreferred food?PreferenceMediumPreferred Colour?PreferenceMedium
7Age?PhysicalLowHeight?PhysicalMediumShoe Size?PhysicalLowPreferred food?PreferenceLowPreferred Colour?PreferenceMedium
8
9
10Age?PhysicalHigh
11Age?PhysicalHigh
12Age?PhysicalMedium
13Age?PhysicalMedium
14Age?PhysicalMedium
15Age?PhysicalLow
16Height?PhysicalLow
17Height?PhysicalHigh
18Height?PhysicalHigh
19Height?PhysicalHigh
20Height?PhysicalHigh
21Height?PhysicalMedium
22Shoe Size?PhysicalMedium
23Shoe Size?PhysicalMedium
24Shoe Size?PhysicalMedium
25Shoe Size?PhysicalHigh
26Shoe Size?PhysicalHigh
27Shoe Size?PhysicalLow
28Preferred food?PreferenceHigh
29Preferred food?PreferenceLow
30Preferred food?PreferenceLow
31Preferred food?PreferenceLow
32Preferred food?PreferenceMedium
33Preferred food?PreferenceLow
34Preferred Colour?PreferenceHigh
35Preferred Colour?PreferenceLow
36Preferred Colour?PreferenceLow
37Preferred Colour?PreferenceMedium
38Preferred Colour?PreferenceMedium
39Preferred Colour?PreferenceMedium
Sheet3
Cell Formulas
RangeFormula
L10:N39L10=VSTACK(L2:N7,O2:Q7,R2:T7,U2:W7,X2:Z7)
Dynamic array formulas.
 
Upvote 0
Thanks that's a good option/idea. My problem is that the actual data set I have is hundreds of noncontiguous columns, and thousands of rows and will be updated monthly. After setting up the vstack it doesn't really need to be dynamic, so probably figuring out a power query will be the most resource efficient way
 
Upvote 0
I did have a look at Power Query, but too my knowledge it might be very difficult. It may be an option to ask the question in the Power Tools section in the forum
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

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