Pivot Table - Count multiple columns

minimini99

New Member
Joined
Oct 5, 2015
Messages
5
I've searched and found 'solutions' to my problem online but the 'solutions' didn't seem to work out for me. Hopefully someone can point me in the right direction.

I'll start by referencing this problem+solution online (Optional reading): excel pivot table - multiple columns - Stack Overflow

Basically, I have a table like so

[TABLE="width: 385"]
<tbody>[TR]
[TD]I like bread[/TD]
[TD]I like cheese[/TD]
[TD]I like milk[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]boy[/TD]
[TD]girl[/TD]
[/TR]
[TR]
[TD]girl[/TD]
[TD]girl[/TD]
[TD]boy[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]boy[/TD]
[TD]boy[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]boy[/TD]
[TD]girl[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]boy[/TD]
[TD]boy[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]girl[/TD]
[TD]boy[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]boy[/TD]
[TD]girl[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]girl[/TD]
[TD]girl[/TD]
[/TR]
[TR]
[TD]girl[/TD]
[TD]boy[/TD]
[TD]girl[/TD]
[/TR]
[TR]
[TD]girl[/TD]
[TD]girl[/TD]
[TD]girl[/TD]
[/TR]
</tbody>[/TABLE]


After using a pivot table, I want the end result to be like so

[TABLE="width: 493"]
<tbody>[TR]
[TD][/TD]
[TD]I like bread[/TD]
[TD]I like cheese[/TD]
[TD]I like milk[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]7[/TD]
[TD]6[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]girl[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]Total[/TD]
[TD]10[/TD]
[TD]10[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]

Following the solutions online, I create a pivot table, throw "I like milk" into the Row Labels, then throw all three "I like ..." into Values.
I end up with something like this:

ztKhmK1.png

(Pic link https://i.imgur.com/ztKhmK1.png )


It looks right at first glance but notice this:
"Count of I like bread" is 4 boys and 6 girls. The correct count would be 7 boys and 3 girls. Same for "Count of I like cheese".

Anyone know what is actually happening and how I can get it to work correctly? Thanks!


Extra task:
Bonus points for someone who can help me get the sum of each row as well, so I would know the number of boys and number of girls. It would look like
[TABLE="width: 557"]
<tbody>[TR]
[TD][/TD]
[TD]I like bread[/TD]
[TD]I like cheese[/TD]
[TD]I like milk[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]boy[/TD]
[TD]7[/TD]
[TD]6[/TD]
[TD]4[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]girl[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]6[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]Total[/TD]
[TD]10[/TD]
[TD]10[/TD]
[TD]10[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello,

it is possible with "Power Query". If you ready to use this then select your table and from PQ menu Excel Data/FromTable and select all columns go to Transform Unpivot columns. After passing all of steps your PQ code should like this:

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"I like bread", type text}, {"I like cheese", type text}, {"I like milk", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value")
in
#"Unpivoted Columns"

and you may use pivot table based on this table.
 
Upvote 0
Hello,

it is possible with "Power Query". If you ready to use this then select your table and from PQ menu Excel Data/FromTable and select all columns go to Transform Unpivot columns. After passing all of steps your PQ code should like this:

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"I like bread", type text}, {"I like cheese", type text}, {"I like milk", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value")
in
#"Unpivoted Columns"

and you may use pivot table based on this table.

I haven't used Power Query before so I'm not familiar with it. Could I know what that does?
 
Upvote 0
because all you need is to make unpivot your table. At the result you'll get the table with two columns. One column will repeat with "I like bread", "I like cheese" and "I like milk" and the other column will repeat with "boy" and "girl". And that is the table that you need to use in pivot table. In pivot table fields use first column in "Columns", and use the second column name in "Rows" and "Values" fields.
 
Upvote 0

Forum statistics

Threads
1,225,149
Messages
6,183,178
Members
453,151
Latest member
Lizamaison

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