How to create table comparing the number of customers who purchased Product A as well as Product C, D, etc...

trojans1975

New Member
Joined
Mar 16, 2015
Messages
3
I'm not sure my title explained it well enough. What I am trying to do is create a crosstab that would have the same column headers as row headers and would show a total count of customers that purchased a product in on segment and also purchased in another segment. For example:

Prod Mrkt CategoryProd AProd BProd C
Prod A100??
Prod B?150?
Prod C??200

<tbody>
</tbody>
so in the above example 100 people purchased prod a. What i need to also show is (looking down the prod a column) How many people purchased prod a AND prod b, how many people purchased prod A AND prod c, etc... Just by doing a basic cross tab i can get the numbers i show above, it's the "?" numbers i really am not sure how to even begin showing.

In my table there is a unique id number for each individual customer so if a customer purchased all 3 products that unique id would be the same for that one customer:

123456 - Joe Smith - Prod A
123456 - Joe Smith - Prod B
123456 - Joe Smith - Prod C

Any help you can provide would be great.

Thanks You
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Oh sorry, I thought this was an Excel question. In Access you might get this to work with a join query, which can be added via the wizard or sql window. I don't have access on this pc right now, I might have the cd rom somewhere. If I can find it I'll try to write something.
 
Upvote 0
Ok in a table named access, I have:


Excel 2010
ABC
1numbernameproduct
2123456Joe SmithProd A
3123456Joe SmithProd B
4789101KermitProd A
5789101KermitProd C
6987654AlfProd A
7987654AlfProd B
8987654AlfProd C
Sheet10


Take a blank query and paste this in the sql view:

Code:
SELECT X.name, X.product, (select count(product) from access where name = x.name and product = "Prod A") AS [Prod A], (select count(product) from access where name = x.name and product = "Prod B") AS [Prod B], (select count(product) from access where name = x.name and product = "Prod C") AS [Prod C]
FROM access AS X;

then in another blank query sql view paste:

Code:
SELECT DISTINCTROW [access Query].product, Sum([access Query].[Prod A]) AS [Prod A], Sum([access Query].[Prod B]) AS [Prod B], Sum([access Query].[Prod C]) AS [Prod C]
FROM [access Query]
GROUP BY [access Query].product;

which should get you:


Excel 2010
ABCD
1productProd AProd BProd C
2Prod A322
3Prod B221
4Prod C212
Sheet11


Is that what you're looking for? Btw, a simple sum or countifs in excel won't be enough for this contrary to what I believed earlier.
 
Upvote 0
This one's better:

Code:
TRANSFORM Sum(1) AS Expr1
SELECT access.product
FROM access AS access_1 INNER JOIN access ON access_1.name = access.name
GROUP BY access.product
ORDER BY access.product, access_1.product
PIVOT access_1.product;
 
Upvote 0
this provided the correct format that i needed but the actual data it output was grossly overstated. I obviously edited it to reflect actual table and/or query names i'm using. In one instance the output in a cell was over 5 times higher than it should have been. There doesn't seem to be a rhyme or reason as to how much each cell is off.
 
Upvote 0

Forum statistics

Threads
1,221,877
Messages
6,162,583
Members
451,776
Latest member
bosvinn

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