如何将列转置为行并确保在excel中相应地重复行?

How to transpose columns into rows and ensure repetition of rows accordingly in excel?

提问人:Chandramouli Raman 提问时间:11/5/2023 最后编辑:Mayukh BhattacharyaChandramouli Raman 更新时间:11/6/2023 访问量:68

问:

如何转置列并确保相应地重复行?

数据集包含以下数据:-

日期 美元 欧元 日元
1/1/1994 1994 1 1 10 20 5
1/1/1995 1995 1 1 12 30 10

预期输出为:-

日期 货币 货币/CCY
1/1/1994 1994 1 1 美元 10
1/1/1994 1994 1 1 欧元 20
1/1/1994 1994 1 1 日元 5
1/1/1995 1995 1 1 美元 12
1/1/1995 1995 1 1 欧元 30
1/1/1995 1995 1 1 日元 10
Excel excel 公式 PowerQuery 转置 数据转换

评论


答:

0赞 Mayukh Bhattacharya 11/5/2023 #1

这可以使用 .要使用上述步骤实现此目的,请按照以下步骤操作:POWER QUERY


  • 首先将源范围转换为表格并相应地命名,在本例中,我将其命名为Table1

  • 接下来,从选项卡 --> 打开一个空白查询DataGet & Transform Data --> Get Data --> From Other Sources --> Blank Query

  • 上面让窗口打开,现在从 Tab --> --> 然后通过删除您看到的任何内容来粘贴以下内容,然后按Power QueryHomeAdvanced EditorM-CodeDone

    let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Date", "Year", "Month", "Day"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Date", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Attribute", "Currency"}, {"Value", "Currency/CCY"}})
in
    #"Renamed Columns"

enter image description here


  • 最后,要将其导入回 --> 单击或 --> 单击的第一个将创建一个具有所需输出的输出,而后者将提示一个窗口,询问您将结果放置在哪里。ExcelClose & LoadClose & Load ToNew Sheet

enter image description here


或者,使用 Excel 公式取消透视其他列

enter image description here


• 细胞中使用的配方A6

=LET(
    _data, A1:G3,
    _matrixOne, TAKE(_data,,4),
    _matrixTwo, DROP(_data,,4),
    _headerOne, TAKE(_matrixOne,1),
    _headerTwo, TAKE(_matrixTwo,1),
    _bodyOne, DROP(_matrixOne,1),
    _bodyTwo, DROP(_matrixTwo,1),
    _diemn, ROWS(_bodyOne)*COLUMNS(_headerTwo),
    _rowDiemn, MOD(SEQUENCE(_diemn,,0),COLUMNS(_headerTwo))+1,
    _rowDiemx, INT((SEQUENCE(_diemn,,0))/COLUMNS(_headerTwo))+1,
    _transformHeader, INDEX(_headerTwo,_rowDiemn),
    _transformMatrixOne, INDEX(_bodyOne,_rowDiemx,SEQUENCE(1,COLUMNS(_matrixOne))),
    _transformMatrixTwo, INDEX(_bodyTwo,SEQUENCE(_diemn,,0)/COLUMNS(_headerTwo)+1,_rowDiemn),
    _topHeader, HSTACK(_headerOne,"Currency","Currency/CCY"),
    _bottomBody, HSTACK(_transformMatrixOne,_transformHeader,_transformMatrixTwo),
    VSTACK(_topHeader,_bottomBody))