【问题标题】:Expand Table with Power Query in multible colums (not in rows)在多列(而不是行)中使用 Power Query 扩展表
【发布时间】:2022-11-25 22:23:20
【问题描述】:

我正在尝试使用 Power Query 连接两个表,但我无助地不知所措。我创建了连接并使用 Left Outer Join 连接了两个表。

表格1

Name Industry Date
Max Mustermann IT 16.10.21
Klaus Dieter ... ...

表 2

Name Question
Max Mustermann Question 1
Max Mustermann Question 2
Klaus Dieter Klaus Question 1
Klaus Dieter Klaus Question 2
Klaus Dieter Klaus Question 3

现在我要输出下表

Name Industry Date Question 1 Question 2 Question 3
Max Mustermann IT 16.10.21 Question 1 Question 2 null
Klaus Dieter ... ... Klaus Question 1 Klaus Question 2 Klaus Question 3

我认为,必须有一种方法可以使用 Table.ExpandTableColumn 命令,但我不知道要搜索什么。

我正在使用 excel 365。

我尝试了 Expand Button 但它只将表 1 与表 2 中的每个条目(具有匹配的名称)连接起来。

【问题讨论】:

    标签: excel powerquery


    【解决方案1】:

    从 Table2 开始并在 Table1 中合并,左外连接匹配 Name

    展开行业和日期

    单击选择名称列,右键单击分组依据

    在每个组中添加一个索引,以便我们可以对问题进行编号。为此,手动调整从组步骤生成的代码,使其结束如下

    {{"data", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type), type table}})
    

    展开数据。单击选择索引列和 Transform .. pivot column 并选择 Question 作为 values 列,然后在 Advanced Options 中,dont aggregate

    表 2 的完整示例代码

    let Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Merged Queries" = Table.NestedJoin(Source, {"Name"}, Table1, {"Name"}, "Table1", JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"Industry", "Date"}, {"Industry", "Date"}),
    #"Grouped Rows" = Table.Group(#"Expanded Table1", {"Name"}, {{"data", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type), type table }}),
    #"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"Question", "Industry", "Date", "Index"}, {"Question", "Industry", "Date", "Index"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded data", {{"Index", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expanded data", {{"Index", type text}}, "en-US")[Index]), "Index", "Question")
    in  #"Pivoted Column"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多