Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I transform rows into repeated column based data?

I'm trying to take a dataset that looks like this:

Source format of data

And transform the records into this format:

Destination Format

The resulting format would have two columns, one for the old column names and one column for the values. If there are 10,000 rows then there should be 10,000 groups of data in the new format.

I'm open to all different methods, excel formulas, sql (mysql), or straight ruby code would work for me also. What is the best way to tackle this problem?

like image 449
OpenCoderX Avatar asked Mar 16 '26 02:03

OpenCoderX


1 Answers

You could add an ID column to the left of your data and use a Reverse PivotTable method.

  • Press Alt+D+P to access the Pivottable Wizard with the steps:

    1.  Multiple Consolidation Ranges
    2a. I will create the page fields
    2b. Range: eg. sheet1!A1:A4 
        How Many Page Fields: 0
    3.  Existing Worksheet: H1
    
  • In the PivotTable:

    Uncheck Row and Column from the Field List
    Double-Click the Grand Total as shown
    

enter image description here

like image 124
lori_m Avatar answered Mar 17 '26 17:03

lori_m