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

如何在Power Query中编写规则实现关键词匹配并输出指定结果

Power Query 实现需求的完整方案

假设你的查询表中已存在value(竖线分隔的靠背类型枚举)和description(商品描述)两个字段,可通过添加自定义列的方式实现所需输出,操作如下:

方案说明

  • 代码默认适配大小写不敏感匹配,避免「High-back」和「high-back」因大小写差异漏匹配
  • 多关键词匹配时默认用逗号分隔输出匹配结果,无匹配时返回空值

方案1:分别添加两个独立输出列

1. 添加「匹配标记」列(输出fix/空)

自定义列公式:

let
  keywordList = List.Transform(Text.Split([value], "|"), Text.Lower),
  descLower = Text.Lower([description]),
  hasMatch = List.AnyTrue(List.Transform(keywordList, (k) => Text.Contains(descLower, k)))
in
  if hasMatch then "fix" else null

2. 添加「匹配关键词」列(输出匹配到的具体值)

自定义列公式:

let
  keywordList = Text.Split([value], "|"),
  descLower = Text.Lower([description]),
  matchList = List.Select(keywordList, (k) => Text.Contains(descLower, Text.Lower(k)))
in
  Text.Combine(matchList, ",")

方案2:合并输出为单个记录列(可选)

如果不想新增过多列,可添加单个「匹配结果」自定义列,后续点击列右上角的扩展按钮,即可一次性得到两个输出字段:

let
  keywordList = Text.Split([value], "|"),
  descLower = Text.Lower([description]),
  matchList = List.Select(keywordList, (k) => Text.Contains(descLower, Text.Lower(k))),
  hasMatch = List.Count(matchList) > 0
in
  [
    匹配标记 = if hasMatch then "fix" else null,
    匹配关键词 = Text.Combine(matchList, ",")
  ]

示例验证

以你给出的测试数据为例:

  • value值:High-back|low-back|Mid-back|No Back
  • description值:Venus Comfort Mesh High-Back Fabric Chair
  • 输出结果:匹配标记为fix,匹配关键词为High-back,符合需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 04:06:04