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

PowerBI:移除文本字段中的特殊字符及后续数字

Hey there! Let's figure out how to remove that underscore _ and any trailing numbers after it from your text values in Power BI. I've got two easy methods for you—pick whichever fits your workflow better:

方法1:用DAX创建计算列

If you want to handle this directly in the report view with a calculated column, use a combination of LEFT(), FIND(), and IFERROR() functions to cover both cases (values with _ and those without).

Here's the formula you can paste into the calculated column editor:

Output Col = 
IFERROR(
    LEFT('Table1'[Input Col], FIND("_", 'Table1'[Input Col]) - 1),
    'Table1'[Input Col]
)

简单拆解下逻辑:

  • FIND("_", 'Table1'[Input Col]) 定位文本中第一个下划线的位置
  • LEFT(..., position - 1) 提取下划线之前的所有字符
  • IFERROR(..., original value) 做容错处理:如果文本里没有下划线(比如"asd"),直接返回原内容,避免报错
方法2:用Power Query(查询编辑器)批量处理

如果你更习惯在数据源层面清洗数据,Power Query有个超直观的函数可以搞定:Text.BeforeDelimiter()。

跟着步骤来:

  1. 打开Power Query编辑器(点击主页选项卡的转换数据)
  2. 选中你的Table1和Input Col列
  3. 点击添加列 > 自定义列
  4. 在公式栏粘贴这段代码:
Text.BeforeDelimiter([Input Col], "_")
  1. 把新列重命名为"Output Col",关闭编辑器即可

这个函数会自动提取第一个下划线之前的内容,如果没有下划线就直接返回原文本——完全适配你的示例场景!

用你的测试数据验证下:

输入值:Abc_1、asd、fgh-abd_5、g_7
输出结果:Abc、asd、fgh-abd、g

两种方法都能得到你想要的结果,选适合你项目的方式就好!

内容的提问来源于stack exchange,提问作者Student of the Digital World

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:46:26