Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Containsstring AND

Hello Everyone,
My goal is to change terms to "C" in two conditions:
1. If terms are A and Mat is X
2. If terms are B and column Mat contains a string XE (in its line item names)
 
I am confused if my usage of Containsstring is right in this case. Please help me out!
 
Column = if(
(
(Table[TERMS] = {"A"} && Table[Mat] in {"X"})
|| (Table[TERMS] = {"B"} && CONTAINSSTRING(Table[Mat],"XE")
),
C,
TABLE[TERMS]
)
 
 
1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi , @Anonymous 

There are some minor errors in format. 

The table name is recommended to be enclosed in quotation marks, and the values "A", "B", "C"  only  need to be enclosed in quotation.

colummn =
IF (
    ( 'Table'[TERMS] = "A"
        && 'Table'[Mat] IN { "X" } )
        || (
            'Table'[TERMS] = "B"
                && CONTAINSSTRING ( 'Table'[Mat], "XE" )
        ),
    "C",
    'Table'[TERMS]
)

 

203.png

 

PS:You can check whether there is an error in the sentence through this website, but the specific error still has to be debugged by yourself
http://www.daxformatter.com/

 

 

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
v-easonf-msft
Community Support
Community Support

Hi , @Anonymous 

There are some minor errors in format. 

The table name is recommended to be enclosed in quotation marks, and the values "A", "B", "C"  only  need to be enclosed in quotation.

colummn =
IF (
    ( 'Table'[TERMS] = "A"
        && 'Table'[Mat] IN { "X" } )
        || (
            'Table'[TERMS] = "B"
                && CONTAINSSTRING ( 'Table'[Mat], "XE" )
        ),
    "C",
    'Table'[TERMS]
)

 

203.png

 

PS:You can check whether there is an error in the sentence through this website, but the specific error still has to be debugged by yourself
http://www.daxformatter.com/

 

 

Best Regards,
Community Support Team _ Eason

Anonymous
Not applicable

HI @Anonymous 

Column = if(((Table[TERMS]="A" && Table[Mat]="X")||(Table[TERMS] = "B" && FIND("XE",Table[Mat])>0),
C,TABLE[TERMS])

 FiND is a better option in this scenario as CONTAiNSSTRiNG is used to match patters and we are not looking for a pattern.

Tahreem24
Super User
Super User

Well, it looks correct. Are you facing any issue while writing that dax?

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard
az38
Community Champion
Community Champion

@Anonymous 

why not? it looks correct but i would write it as

Column = if(
(
(Table[TERMS] = "A" && Table[Mat] = "X")
|| 
(Table[TERMS] = "B" && CONTAINSSTRING(Table[Mat],"XE")
),
C,
TABLE[TERMS]
)

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.