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

Power BI中基于切片器选中文本与其他文本的匹配词数计算需求

问题描述

现有一张包含id和text两列的表格,数据如下:

id  text
765 hi how are you
876 John made $57.
743 apple is my favourite fruit.
435 mango is not my favorite fruit.
892 this is my favourite movie

要求将id列设置为切片器,选择任意一个id(例如743)后,输出所有id、对应text,以及所选id的文本与各条文本的匹配词数,期望输出如下:

id  text                             matching words
743 apple is my favourite fruit.       5
765 hi how are you                     0
876 John made $57.                     0
435 mango is not my favorite fruit.    4
892 this is my favourite movie         3
解决方案(以Power BI为例)

步骤1:获取选中的目标文本

创建度量值提取切片器选中id对应的文本:

Selected Text = SELECTEDVALUE('Table'[text])

步骤2:统计匹配词数

创建度量值完成文本拆分、清洗和匹配计数:

Matching Words Count = 
VAR SelectedWords = SPLIT([Selected Text], " ", TRUE())
VAR CurrentWords = SPLIT('Table'[text], " ", TRUE())
-- 清洗文本:去除句号、转小写、去首尾空格
VAR CleanSelectedWords = 
    SELECTCOLUMNS(
        SelectedWords,
        "CleanWord", LOWER(TRIM(SUBSTITUTE([Value], ".", "")))
    )
VAR CleanCurrentWords = 
    SELECTCOLUMNS(
        CurrentWords,
        "CleanWord", LOWER(TRIM(SUBSTITUTE([Value], ".", "")))
    )
-- 计算交集行数即匹配词数
RETURN COUNTROWS(INTERSECT(CleanSelectedWords, CleanCurrentWords))

步骤3:构建结果表

在Power BI中新建表可视化,添加id、text字段和Matching Words Count度量值,即可实现需求效果。

说明:代码做了基础文本清洗,若需处理更多标点(如$)或拼写差异(如favourite/favorite),可在SUBSTITUTE中添加更多替换规则,或引入拼写匹配逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 13:05:29