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

Power Query多条件匹配另一表格获取Conf值的实现问题

Power Query 匹配TABLE2的Conf值解决方案

直接在TABLE1中添加自定义列,通过筛选+排序取目标记录的方式实现需求,具体M代码如下:

let
    // 加载TABLE1和TABLE2(根据实际数据源调整这两行)
    Source_Table1 = Excel.CurrentWorkbook(){[Name="TABLE1"]}[Content],
    Source_Table2 = Excel.CurrentWorkbook(){[Name="TABLE2"]}[Content],
    // 为TABLE1添加自定义列匹配Conf值
    Add_Conf_Column = Table.AddColumn(Source_Table1, "Conf", each 
        let
            Current_Order = [Order],
            Current_Seq = [Seq],
            Current_Op = [Op],
            // 筛选TABLE2中符合条件的记录
            Filtered_Table2 = Table.SelectRows(Source_Table2, 
                (row) => row[Order] = Current_Order 
                        and row[Seq] = Current_Seq 
                        and row[Op] < Current_Op),
            // 如果有匹配记录,按Op降序排序后取第一条的Conf;否则返回null
            Result = if Table.RowCount(Filtered_Table2) > 0 then 
                        Table.First(Table.Sort(Filtered_Table2, {{"Op", Order.Descending}}))[Conf]
                     else null
        in
            Result)
in
    Add_Conf_Column

代码说明:

  • Table.SelectRows 完成核心筛选:匹配Order、Seq,且TABLE2的Op小于当前TABLE1行的Op
  • Table.Sort 按Op降序排列,确保最接近当前Op的记录排在首位
  • Table.First 取排序后的第一条记录的Conf值,无匹配时返回null

如果你的TABLE1/TABLE2是从其他数据源加载的,只需修改Source_Table1和Source_Table2的获取逻辑即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 19:58:13