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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Correct DAX syntax for using SWITCH and Contains together.

Hi All, 

New to the forum and Power Bi.  I am currently trying to figure out how to classify various codes to Products in my query.  The trick is that some codes are utilized expressly for a given product while for others variations are used. A nested IF may be a possibility, but I am currently trying to use SWITCH in conjunction with "Contains" for the cases where a variation of the code is being used.  Here is an excerpt on how i currently have the DAX formula set up:

SWITCH(TRUE(),

'Code Load'[Billing ID]="ESEAT3", "Seats",

'Code Load'[Billing ID]Contains "EECI", "Superior Svc"

 

I am currently getting an error on synatax for "Contains".  Any insight would be appreciated.  Thanks all.

 

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

Jihwan_Kim_0-1707069546833.png

 

 

CONTAINSSTRING function (DAX) - DAX | Microsoft Learn

 

Expected result CC = 
SWITCH (
    TRUE (),
    'Code Load'[Billing ID] = "ESEAT3", "Seats",
    CONTAINSSTRING ( 'Code Load'[Billing ID], "EECI" ), "Superior Svc"
)

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

Anonymous
Not applicable

Disregard my earlier send re useing CONTAINS in a nested statement.  Your solution works PERFECTLY.  Thanks for the quick response!!!

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Disregard my earlier send re useing CONTAINS in a nested statement.  Your solution works PERFECTLY.  Thanks for the quick response!!!

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

Jihwan_Kim_0-1707069546833.png

 

 

CONTAINSSTRING function (DAX) - DAX | Microsoft Learn

 

Expected result CC = 
SWITCH (
    TRUE (),
    'Code Load'[Billing ID] = "ESEAT3", "Seats",
    CONTAINSSTRING ( 'Code Load'[Billing ID], "EECI" ), "Superior Svc"
)

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

This looks very good.  Question, how do i next the CONTAINSSTRING to utilize with multiple codes?  Thanks.

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.