Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

if statement - Switch (True); The same column contain multiple search criteria in Power BI

  1. If column A contain "TP" then "Yes".
  2. If column A contain "TP-" then "Yes".
  3. If column A contain "-A" then "Yes".
  4. If column A does not contain "TP","TP-","-A" then desired result is "No".

In Excel I am applying the following formula in order to get the my final result.

=IF(SUM(COUNTIF(A2,{"*TP","*TP-*","*-A*"})),"YES","NO")

Note:

Column A contain text and numbers and Prefix and suffix or prefix with suffix as well.

DATA and DESIRED RESULT;

ITEM        DESIRED RESULT
1234567TP           YES
1234567TP-0001      YES
1234567TP-0001DR    YES
1234567TP-DR0001DR  YES
1234567TP-A0006DR   YES
1234567TP-A90001DR  YES
1234567TP-A0001DR   YES
7674859YO-A891      YES
456YO-A12           YES
87654HI-A0000098    YES
1234678VU           NO
1234678VU-P00094    NO
1234678VU-P00089    NO
1234678VU-P00567    NO

enter image description here

question from:https://stackoverflow.com/questions/65830597/switch-true-the-same-column-contain-multiple-search-criteria-in-power-bi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use this DAX formula to obtain the expected result:

Desired Column = 
IF( 
    CONTAINSSTRING( 'Table'[ITEM], "TP" ), "YES", 
    IF( 
        CONTAINSSTRING( 'Table'[ITEM], "TP-" ), "YES",
        IF( 
            CONTAINSSTRING( 'Table'[ITEM], "-A" ), "YES",  "NO"
        )
    )
)

Just to mention, the "TP-" condition is not needed because you have the "TP" condition. I just added to keep your logic.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...