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

Power Query中基于另一列前缀替换列值的代码问题求助

问题定位与修复方案
  • 核心错误:你代码里的Text.Start(Text.From([Description]),1)只取了Description值的第一个字符,拿它和完整的"monthly_Total"比较,肯定永远匹配不上,这就是操作失败的根源。

  • 修正后的代码(推荐用Text.StartsWith,更省心):

= Table.ReplaceValue(#"Renamed Columns",
    each [Category],
    each if Text.StartsWith(Text.From([Description]), "monthly_Total") then "Accounting Adjustments" 
         else [Category],
    Replacer.ReplaceText,{"Category"})
  • 要是非要用Text.Start的话,得把第二个参数改成目标前缀的长度("monthly_Total"一共12个字符):
= Table.ReplaceValue(#"Renamed Columns",
    each [Category],
    each if Text.Start(Text.From([Description]),12) = "monthly_Total" then "Accounting Adjustments" 
         else [Category],
    Replacer.ReplaceText,{"Category"})
  • 额外提醒:如果Description列有空值或者非文本类型,最好加个空值判断避免报错:
each if [Description] <> null and Text.StartsWith(Text.From([Description]), "monthly_Total") then "Accounting Adjustments" 
     else [Category]

要是前缀大小写可能不统一,还可以忽略大小写匹配:把Text.StartsWith改成Text.StartsWith(Text.From([Description]), "monthly_Total", Comparer.OrdinalIgnoreCase)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 16:53:19