Convert matrix to 3-column table ('reverse pivot', 'unpivot', 'flatten', 'normalize')

后端 未结 3 1852
长发绾君心
长发绾君心 2020-11-21 05:44

I need to convert the Excel matrix FIRST in the table LATER:

FIRST:



        
3条回答
  •  独厮守ぢ
    2020-11-21 06:30

    Another way to unpivot data without using VBA is with PowerQuery, a free add-in for Excel 2010 and higher, available here: http://www.microsoft.com/en-us/download/details.aspx?id=39379

    Install and activate the Power Query add-in. Then follow these steps:

    Add a column label to your data source and turn it into an Excel Table via Insert > Table or Ctrl - T.

    enter image description here

    Select any cell in the table and on the Power Query ribbon click "From Table".

    enter image description here

    This will open the table in the Power Query Editor window.

    enter image description here

    Click the column header of the first column to select it. Then, on the Transform ribbon, click the Unpivot Columns drop-down and select Unpivot other columns.

    For versions of Power Query that don't have the Unpivot other columns command, select all columns except the first one (using Shift-click on the column headers) and use the Unpivot command.

    enter image description here

    The result is a flat table. Click Close and Load on the Home ribbon and the data will be loaded onto a new Excel sheet.

    enter image description here

    Now to the good part. Add some data to your source table, for example

    enter image description here

    Click on the sheet with the Power Query result table and on the Data ribbon click Refresh all. You will see something like:

    enter image description here

    Power Query is not just a one-time transformation. It is repeatable and can be linked to dynamically changing data.

提交回复
热议问题