excel 使用Power Query同时展开所有列

zqdjd7g9  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(229)

使用Power Query同时展开电子表格中的所有列。我把电子表格从这里转过来:
转置列:(https://i.stack.imgur.com/vZnnY.png
展开一列:(https://i.stack.imgur.com/qf9Rp.png
展开所有列:(https://i.stack.imgur.com/v3FYk.png
在excpand列之后,其创建重复数据
我现在使用的是这个代码:

let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Renamed Columns" = Table.RenameColumns(Source,{{"instrument_key", "Symbol1"}}),
    #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "Symbol.1", each Symbol([Symbol1])),
    #"Removed Columns" = Table.RemoveColumns(#"Invoked Custom Function",{"symbol", "year", "W/M", "Strike", "Option", "Symbol1", "tradingsymbol", "Lot"}),
    #"Transposed Table" = Table.Transpose(#"Removed Columns")
in
    #"Transposed Table"

我期待展开所有列一个接一个witout像这样重复
就像这样:(https://i.stack.imgur.com/AR0R1.png

jgovgodb

jgovgodb1#

如果总是有3列和一行,并且开始是Source,则

ColNames =Table.ColumnNames(Source{0}[Column1])& List.Transform(Table.ColumnNames(Source{0}[Column2]), each _&"_2")& List.Transform(Table.ColumnNames(Source{0}[Column3]), each _&"_3"),
Combined = Table.ToColumns(Source{0}[Column1]) & Table.ToColumns(Source{0}[Column2]) & Table.ToColumns(Source{0}[Column3]),
Expand=Table.FromColumns(Combined,ColNames)

相关问题