假设我在 Excel 中有一个 Power 查询,它生成如下数据:
Col1 Col2 Col3
Item11 Item12 Item13
Item21 Item22 Item23
Item31 Item32 Item33
Item41 Item42 Item43
并且我想使用另一个强力查询成对地连接连续的行:
Col1A Col2A Col3A Col1B Col2B Col3B
Item11 Item12 Item13 Item21 Item22 Item23
Item31 Item32 Item33 Item41 Item42 Item43
有没有办法做到这一点?
答案1
如果我正确理解了您的问题,则以下操作应该有效:
- 使用 Table.Group 按对进行分组
- 通过以下方式将每对展平为一行
- 逆透视至两列
- 将正确的列名称放入属性列中
- 重新转到属性列
let
Source = Excel.CurrentWorkbook(){[Name="Table8"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}, {"Col3", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Inserted Integer-Division" = Table.AddColumn(#"Added Index", "Integer-Division", each Number.IntegerDivide([Index], 2), Int64.Type),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Integer-Division",{"Index"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"Integer-Division"}, {
{"Flatten", (t)=>let
#"Unpivot" = Table.UnpivotOtherColumns(Table.RemoveColumns(t,"Integer-Division"),{},"Columns","Values"),
#"Add Index" = Table.AddIndexColumn(#"Unpivot","Index"),
#"Integer-Div" = Table.AddColumn(#"Add Index","IntDiv", each Number.IntegerDivide([Index], Table.RowCount(#"Add Index")/2)),
#"Rem Index" = Table.RemoveColumns(#"Integer-Div","Index"),
#"Col Names" = Table.AddColumn(#"Rem Index","ColNames", each [Columns] & "_" & Character.FromNumber([IntDiv] + 65)),
#"Rem Cols" = Table.RemoveColumns(#"Col Names",{"Columns","IntDiv"}),
#"Pivot" = Table.Pivot(#"Rem Cols", #"Rem Cols"[ColNames], "ColNames", "Values")
in
#"Pivot"
}}),
#"Removed Columns1" = Table.RemoveColumns(#"Grouped Rows",{"Integer-Division"}),
#"ColNames" = Table.ColumnNames(#"Removed Columns1"{0}[Flatten]),
#"Expanded Flatten" = Table.ExpandTableColumn(#"Removed Columns1", "Flatten",
#"ColNames"),
#"Set Types" = Table.TransformColumnTypes(#"Expanded Flatten",
List.Transform(#"ColNames", each {_, type text}))
in
#"Set Types"
答案2
我假设您正在寻找的不仅仅是连接功能,但如果不是……这就是我所想的。如果我们假设:
- Col1 从 A 开始
- Col1A 从 G 开始。
举例来说,我在中间放置两个空格和破折号来分隔来自不同单元格的输入。
=CONCAT(A2," - ",G2)
结果将是“Item11 - Item11”
https://support.microsoft.com/en-us/office/concat-function-9b1a9a3f-94ff-41af-9736-694cbd6b4ca2