Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...