How can I turn part of the Excel data to columns to get a desired output?

倖福魔咒の 提交于 2019-11-26 22:09:58

问题


For eg - Say I have data in the following format -

Current Format

I would need the data to be formatted in the following format for ease of use -

Required Format

Of course the data contains a lot more records - I'm looking for an easy way to transpose data in this way for large sets of data.

Any help will be appreciated :)


回答1:


This is very easy with PowerQuery. It is inbuilt for Excel 2016 and a freely available add in for Version from 2010 to 2013.

You would set your data up as a table excluding the first row which contains the text Number of Cases (Ctrl + T whilst bring up window to create table)

Then from the data tab (Excel 2016) or the Powerquery tab (earlier versions) select data from table and use your newly created table as source.

Highlight the last 3 columns and right click > unpivot columns

Double click in headers section and rename Attribute as Type and Value as Number of Cases

Top left select close and load to

Select table and load to new worksheet (or existing)

View result




回答2:


What you want to do is called:

Unpivot:

  1. Select the data and on the Insert menu choose Table
  2. On the Data menu click From Table/Range
  3. The query window will open. Choose the columns you need to extract. With your data the columns to highlight are "Type" and "Number of Cases"
  4. On the Tranform menu choose Unpivot Columns
  5. If the data looks right now, close the Query Editor (accepting changes).

Examples here: Unpivot Excel Data



来源:https://stackoverflow.com/questions/47505648/how-can-i-turn-part-of-the-excel-data-to-columns-to-get-a-desired-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!