Forum Discussion
JK-1
1 year agoHelper 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. ...
- 1 year ago
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",
""
)
Anonymous
1 year agoNot applicable
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.