You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何提升Power Query中Table.Combine()的表格合并性能?

关于Table.Combine()性能优化的问题

我有一组列结构不同的表格(实际数据),合并后得到含15列的表格。实际数据中,这些表格由前置步骤生成,每步耗时均不到1秒,但仅Table.Combine()处理约1200行数据时耗时近2分钟。为便于演示,以下仅展示4列的输出效果。

是否存在更快的替代方法,能得到与Table.Combine()完全一致的输出?感谢您的帮助。


当前使用的查询代码

let
    Tables = {
        Table.FromRecords({[Name = "Bob", Phone = "123-4567"],
                           [Name = "",Phone = ""]
                          }),
        Table.FromRecords({[Fax = "987-6543", Phone = "838-7171"],
                           [Fax = "", Phone = "233-687"],
                           [Fax = "", Phone = "544-778"]
                         }),
        Table.FromRecords({[Cell = "543-7890"],
                           [Cell = ""],
                           [Cell = ""]
                          })
    },
    CombinedTable = Table.Combine(Tables)
in
    CombinedTable

当前输出

合并后的表格包含Name、Phone、Fax、Cell四列,共8行数据,具体内容如下:

  • 第1行:Name=Bob,Phone=123-4567,Fax=null,Cell=null
  • 第2行:Name="",Phone="",Fax=null,Cell=null
  • 第3行:Name=null,Phone=838-7171,Fax=987-6543,Cell=null
  • 第4行:Name=null,Phone=233-687,Fax="",Cell=null
  • 第5行:Name=null,Phone=544-778,Fax="",Cell=null
  • 第6行:Name=null,Phone=null,Fax=null,Cell=543-7890
  • 第7行:Name=null,Phone=null,Fax=null,Cell=""
  • 第8行:Name=null,Phone=null,Fax=null,Cell=""

更新内容

以下是添加了Table.Buffer()到group5步骤后的完整查询:

let
     Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jVNdb4JAEPwvPFty3KHUR1C4Sg+0x5lqqSF+tGlqH5q0mv787hkal41FEsLNLjczu5NQlk6kpqP7yixnceU5Pad+Vr3SCQF4qI4A9FE9AiBQXcyj6qTWlBkDYKiOSd1C8wkNTyPpdK174DntHpzscUucB8R5iOqE6rU6B1ecOXEeEueOUXmE5nejBS1uCZHt6C5JnCge3mReiiMLJ/mNELidARgZreMCNTWAsQozPMgC0N2DFbHK8unUTTOr9XxgTGzzuVIn9AKtRZrDe7M5uod3xrj7uf8I2MD9Or7u1t9rxA2VmsJRGIPui//vX/CK8rOX7zHLFXBgbntM9L+T01koSUaRnvQNiciEanw1Ir37gSLZ7mx/Uw/qcbFvDKjjFD7Bijq1Eywf64uC87egWwzS/xP3hmfG6hc=", BinaryEncoding.Base64), Compression.Deflate)),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [COL1 = _t, COL2 = _t, COL3 = _t, COL4 = _t]
  ),
    
    fx = each not List.IsEmpty(List.RemoveItems(_,{"",null})),
    
    group0 = Table.Group(Source, "COL2", {"n", each _}, 0, (x, y) => Byte.From(y = "" or y = null)), 
    group1 = Table.TransformColumns(
      group0, 
      {
        "n", 
        each 
          let
            a = Table.Skip(_), 
            b = Table.FirstN(a, each [COL3] = "" or [COL3] = null), 
            c = Table.Skip(a, Table.RowCount(b))
          in
            [a = a, b = b, c = c]
      }
    ), 
    group2 = Table.TransformColumns(
      group1, 
      {"n", each Table.ToColumns(Table.Transpose([b])) & Table.ToColumns([c])}
    ), 
    group3 = Table.TransformColumns(group2, {"n", each List.Select(_, fx)}), 
    group4 = Table.TransformColumns(group3, {"n", each Table.FromColumns(_)}), 
    group5 = Table.Buffer( Table.TransformColumns(group4, {"n", each Table.PromoteHeaders(_)})  ) , 
    combine = Table.Combine(group5[n]), 
    Custom1 = Table.SelectRows(combine, each fx(Record.ToList(_)))
in
  Custom1

该查询的目的是将重复块+子块形式的原始数据整理为规范表格:
原始数据以块为单位重复,每个块包含标题行和多行子数据,部分行用空值占位。

查询输出为规范结构化表格:所有有效数据按列对齐,自动移除了全空行。


内容的提问来源于stack exchange,提问作者Rasec Malkic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 22:01:00