Home » Questions » Computers [ Ask a new question ]

How to "unpivot" or "reverse pivot" in Excel?

How to "unpivot" or "reverse pivot" in Excel?

I have data that looks like this:

Asked by: Guest | Views: 92
Total answers/comments: 5
Guest [Entry]

"You can do this with a pivot table.

Create a ""Multiple Consolidation Ranges PivotTable."" (Only on Pivot Table Wizard. Callup with ALT+D, P on Excel 2007)
Select ""I will create my own page fields"".
Select your data.
Double click on the grand total value - the one at the intersection of Row Grand and Column Grand, all the way on the lower right hand corner of your pivot table.

You should see a new sheet containing all of the data in your pivot table, transposed in the way you're looking for.

Datapig technologies provides step-by-step instructions that are actually more complicated than you need - his example transposes only part of the data set & uses the pivot technique combined with TextToColumns. But it does have lots of pictures.

Note that a pivot table will group the data. If you want it ungrouped, the only way to do it is to copy the pivot table, and ""paste special"" as values. You can then fill in the blanks with a technique like this: http://www.contextures.com/xlDataEntry02.html"
Guest [Entry]

I have built an add-in that will let you do that, and that makes it easy to adapt to different situations. Check it out here: http://tduhameau.wordpress.com/2012/09/24/the-unpivot-add-in/
Guest [Entry]

"If the dimensions of your data are as in the sample provided in your question, then the following set of formulae using OFFSET should give you your required result:
Assuming

1 | NY | CA | TX | IL
2 | WA | OR | NH | RI

are in the range A2:E3, then enter

=OFFSET($A$2,FLOOR((ROW(A2)-ROW($A$2))/4,1),0)

in F2, say, and

=MOD(ROW(A2)-ROW($A$2),4)+1

in G2, say, and

=OFFSET($B$2,FLOOR((ROW(B2)-ROW($B$2))/4,1),MOD(ROW(A2)-ROW($A$2),4))

in H2, say.
Then copy these formulae down as far as required.
This is the easiest, pure, built-in formula solution that I can think of."
"If the dimensions of your data are as in the sample provided in your question, then the following set of formulae using OFFSET should give you your required result:
Assuming

1 | NY | CA | TX | IL
2 | WA | OR | NH | RI

are in the range A2:E3, then enter

=OFFSET($A$2,FLOOR((ROW(A2)-ROW($A$2))/4,1),0)

in F2, say, and

=MOD(ROW(A2)-ROW($A$2),4)+1

in G2, say, and

=OFFSET($B$2,FLOOR((ROW(B2)-ROW($B$2))/4,1),MOD(ROW(A2)-ROW($A$2),4))

in H2, say.
Then copy these formulae down as far as required.
This is the easiest, pure, built-in formula solution that I can think of."
Guest [Entry]

"You seem to have gotten the ""loc"" column (evidenced by your first answer), and now you need help getting the other two columns.

Your first option is to simply type the first several (say, 12) rows into those columns and drag down - I think Excel does the right thing in this case (I don't have excel on this computer to test it for sure).

If that doesn't work, or if you want something more programmer-y, try using the row() function. Something like ""=Floor(row()/4)"" for the ID column and ""=mod(row(),4)+1"" for the LocNum column."
Guest [Entry]

"There is a parametric VBA conversion utility to unpivot or reverse pivoted data back to a database table, please see

http://www.spreadsheet1.com/unpivot-data.html"