超级查询:如何使超级查询更新合并文件?

问题描述 投票:0回答:1

我有两个合并的文件。

我想定期更新这些文件,有时可以添加一列或更改列名。

但是,当列名更改时,它在生成的合并文件中不会更改。

我想让我的“合并查询”发展起来,以便它用潜在的新输入进行“更新”。例如,如果要合并的文件之一具有另外一列或新名称,我希望我的查询反映出来。

如何更改查询中的内容?这可能吗?

下面是我要解决的最小示例:

文件一:

  |---------------------|---------------------|  
  |       Name          |      Pro1           |      
  |---------------------|---------------------|
  |         A           |         56          |     
  |---------------------|---------------------|
  |         B           |         56          |     
  |---------------------|---------------------|

文件2:

  |---------------------|---------------------|  
  |       Name          |       WEURK         |      
  |---------------------|---------------------|
  |         A           |       LALALA        |     
  |---------------------|---------------------|
  |         B           |       RTEWRFVE      |     
  |---------------------|---------------------|

合并结果:

  |---------------------|---------------------|---------------------|    
  |       Name          |      Pro1           |       WEURK         |      
  |---------------------|---------------------|---------------------|
  |         A           |         56          |       LALALA        |        
  |---------------------|---------------------|---------------------|
  |         B           |         56          |       RTEWRFVE      |      
  |---------------------|---------------------|---------------------|

但是,在这里,我进行了以下操作:更改列名,但这对我的合并没有影响...如何使合并成为“更新”?

  |---------------------|---------------------|  
  |       Name          |    WALALLALALALA    |      
  |---------------------|---------------------|
  |         A           |         56          |     
  |---------------------|---------------------|
  |         B           |         56          |     
  |---------------------|---------------------|
merge powerbi refresh updates powerquery
1个回答
0
投票

您可以使用Table.ColumnNames获取可能更改的表列名称的列表。

这里是一个最小可能的查询。

let
    // Column names in File2 except for "Name" column.
    #"File2 Columns" =
        List.RemoveItems(Table.ColumnNames(File2), {"Name"}),

    // Merge File2 into a nested table column named "__File2".
    // You may need to replace JoinKind to another one depending on your data.
    #"Merged Queries" =
        Table.NestedJoin(File1, {"Name"}, File2, {"Name"}, "__File2", JoinKind.FullOuter),

    // Expand all the columns except for "Name" in the nested "__File2" table.
    #"Expanded File2" =
        Table.ExpandTableColumn(#"Merged Queries", "__File2", #"File2 Columns")
in
    #"Expanded File2"

此查询过于简化以致无法实际应用,因为它假设诸如合并键列“ Name”将不会更改,并且File1和File2中没有重复的列名。

但这将是您的起点。

© www.soinside.com 2019 - 2024. All rights reserved.