Power BI-搜索并包含和排除某些字符串

时间:2018-07-26 15:18:07

标签: powerbi

我有一张简单的桌子:

Column            Desired result
Messi Ronaldo     0
Ronaldo           0
Messi Pogba       0
Messi alala       1

然后我尝试计算字符串中梅西出现了多少次,而Ronaldo和Pogba都不存在了。

我得到的代码是:

Desired result = 
IF (ISBLANK ( SEARCH ( "Messi", 'Table'[Column], 1, BLANK () ) )
&&
(
ISBLANK ( SEARCH ( "Ronaldo", 'Table'[Column], 1, BLANK () ) )
||ISBLANK ( SEARCH ( "Pogba", 'Table'[Column], 1, BLANK () ) )
)
,
0,
1)

但是它不排除Ronaldo或Pogba吗?

当前(错误)结果

Column           Current results
Messi Ronaldo    1
Ronaldo          0
Messi Pogba      1
Messi alala      1

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

Desired result = 
    IF (NOT(ISBLANK ( SEARCH ( "Messi",   'Table'[Column], 1, BLANK () ) ))
        &&  ISBLANK ( SEARCH ( "Ronaldo", 'Table'[Column], 1, BLANK () ) )
        &&  ISBLANK ( SEARCH ( "Pogba",   'Table'[Column], 1, BLANK () ) ),
        1,
        0)

如果搜索“ Messi”没有返回空格,但搜索“ Ronaldo”和“ Pogba”却返回了空白,则返回1