Generating matrix using Microsoft Excel’s Pivot Tables

Often times there is a need to generate a matrix. For simplicity sake, let’s assume that you have a table containing Products and States in which they are sold. Microsoft Excel has a very efficient utility called pivot tables which one can leverage to generate the required matrix.

For example :

 

Product

States

P1

NC

P1

PA

P1

WA

P2

NC

P2

NY

P3

MI

P4

CA

P4

AZ

P4

NC

P5

FL

 

 

And if the desired output is :

 

Product

AZ

CA

FL

MI

NC

NY

PA

WA

P1

 

 

 

 

1

 

1

1

P2

 

 

 

 

1

1

 

 

P3

 

 

 

1

 

 

 

 

P4

1

1

 

 

1

 

 

 

P5

 

 

1

 

 

 

 

 

 

Following are the steps to generate the desired output using Microsoft Excel’s Pivot tables

1. Go to Data –> PivotTable and Pivot Chart Report
2. On Pivot Table and Pivot Chart Wizard Step 1 of 3
2a. Select the Microsoft Office Excel List or database
2b. Select “Pivot Table” for the 2nd question.
2c. Click “Next.
3. Select range (where your data resides on the worksheet) and click next
4. Determine where you want to put this pivot table and click next
5. Click Finish
6. Drag and Drop the “Product” in “Drop Row Fields Here” area.
7. Drag and Drop the “States” in “Drop Column Fields Here” area.
8. Drag and Drop the “States” in “Drop Data Items Here” area.
9. Done!

If you have a product which is not being sold in any states and if you want to show it on the matrix, you can add a row to the product/states table. Set the value of state to . If you followed the above mentioned process all you will have to do is right click on the pivot table area and hit “Refresh Data”, your matrix will be updated in a split second!

5 Responses to “Generating matrix using Microsoft Excel’s Pivot Tables”

  1. Venkat says:

    How to do the reverse of this thing??

  2. Chetan Shah says:

    Thanks for the query but unfortunately I don’t know how to do that. If I find out I will post it on my blog.

    Thanks for your time.

  3. Nestor says:

    Thank you, this is exactly what I was looking for, just one more question: is it possible to convert the 1’s to another symbol, such as x or checkmark?

    Thanks;

  4. Matthew Peroni says:

    Wow! Really awesome post! :)
    … Question: What version of excel did you use?

  5. Chetan Shah says:

    Excel 2003

Leave a Reply