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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
JK-1
Helper II
Helper II

DAX switch but using containsstring

Is there a way to have CONTAINSSTRING in the below instead, as using IN as part of the VAR _Name requires an exact, and I have some examples elsewhere where it would be easier to use containsstring. I've tried a few different IF CONTAINSSTRING in places, and substituted TRUE but can't get it to work

 

Result = VAR _Name = 'Table1'[Name]
RETURN
SWITCH(
TRUE(),
_Name IN {"South"},
"30",
_Name IN {"North"},
"28",
_Name IN {"East"},
"22",
_Name IN {"West"},
"20",
""
)

 

thanks in advance

1 ACCEPTED SOLUTION
Shahid12523
Community Champion
Community Champion

Yes — replace IN with CONTAINSSTRING inside SWITCH(TRUE())

 

Result =
VAR _Name = 'Table1'[Name]
RETURN
SWITCH(
TRUE(),
CONTAINSSTRING(_Name, "South"), "30",
CONTAINSSTRING(_Name, "North"), "28",
CONTAINSSTRING(_Name, "East"), "22",
CONTAINSSTRING(_Name, "West"), "20",
""
)

Shahed Shaikh

View solution in original post

2 REPLIES 2
v-agajavelly
Community Support
Community Support

Hi @JK-1 ,

Did you get a chance to try the @Shahid12523  suggestion with CONTAINSSTRING inside SWITCH(TRUE())? It should work as expected for example, "South Region" would correctly return 30. Just note that if a name contains more than one of the keywords (like "NorthEast"), the formula will stop at the first match it finds, so only "North" would be applied in that case. Otherwise, the approach should give you the results you’re looking for.

Regards,
Akhil.

Shahid12523
Community Champion
Community Champion

Yes — replace IN with CONTAINSSTRING inside SWITCH(TRUE())

 

Result =
VAR _Name = 'Table1'[Name]
RETURN
SWITCH(
TRUE(),
CONTAINSSTRING(_Name, "South"), "30",
CONTAINSSTRING(_Name, "North"), "28",
CONTAINSSTRING(_Name, "East"), "22",
CONTAINSSTRING(_Name, "West"), "20",
""
)

Shahed Shaikh

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.