[英]How to convert multi column excel table to single column with header attached
If you have Excel O365, you could opt for:如果您有 Excel O365,您可以选择:
Formula in E1
: E1
中的公式:
=SORT(TRANSPOSE(CHOOSE({1,2},TRANSPOSE(FILTERXML("<t><s>"&TEXTJOIN("</s><s>",,A2:C4&"</s><s>"&A1:C1)&"</s></t>","//s[position() mod 2 = 1]")),TRANSPOSE(FILTERXML("<t><s>"&TEXTJOIN("</s><s>",,A2:C4&"</s><s>"&A1:C1)&"</s></t>","//s[position() mod 2 = 0]")))),1,1)
You can use Power Query, available in Excel 2010+您可以使用 Excel 2010+ 中提供的 Power Query
It is a part of Excel 2016+ and available as a free Microsoft provided add-in in the earlier versions.它是 Excel 2016+ 的一部分,在早期版本中作为免费的 Microsoft 提供的插件提供。
Data / Get & Transform / From Table/Range
A
, B
and C
are not the Headers
then (In the Power Query UI)A
、 B
和C
不是Headers
,则(在 Power Query UI 中)
Home / Transform / Use First Row as Headers
Transform / Any Column / Unpivot Columns
Attribute
and Value
, in that orderAttribute
和Value
排序Value
column to the first column positionValue
列移动到第一列 positionHome / Close / Close & Load
All of the above steps can be done from the Power Query UI, but here is the generated M-Code上述所有步骤都可以从 Power Query UI 完成,但这里是生成的 M-Code
M-Code M-代码
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
#"Sorted Rows" = Table.Sort(#"Unpivoted Columns",{{"Attribute", Order.Ascending}, {"Value", Order.Ascending}}),
#"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"Value", "Attribute"})
in
#"Reordered Columns"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.