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

CASE Complex statement in DAX

Hello! 🙂 

I am trying to "translate" a complex case statement in DAX. I have tried 'Switch function' and it's OK:

 

New field = SWITCH (

        TRUE (),

table1[Category] = "hair-color", "LUXE",

table1[Category] = "hair-care", "LUXE",

table1[Category] = "hair-style", "LUXE",

...etc

"Other"

)

 

What's the problem? When within the case statement I have more options for the same string:

 

CASE
WHEN REGEXP_MATCH(Field 1, ".*Hair-Color.*|.*Hair-Care.*|.*Hair-Style.*") THEN "Hair"
WHEN REGEXP_MATCH(Field 1, ".*Skin-Sun.*|.*Skin-Face.*|.*Skin-Body.*") THEN "Skin"

... etc

ELSE "Other"

END

 

How can I translate every of these options: ".*Skin-Sun.*|.*Skin-Face.*|.*Skin-Body.*"|...etc" within my Switch function in DAX?

 

Thanks so much in advance! 🙂 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , You can try like

New field = SWITCH (
TRUE (),
table1[Category] in ("hair-color","hair-care","hair-style"), "LUXE",
"Other"
)

 

But if need to search then you need use search, check

https://youtu.be/mZt0HJw4gjQ

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

This might work?

_newField =
SWITCH(
  TRUE(),
  CONTAINSSTRING(table1[Category], "Hair"), "Hair",
  CONTAINSSTRING(table1[Category], "Skin"), "Skin",
  ...
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




amitchandak
Super User
Super User

@Anonymous , You can try like

New field = SWITCH (
TRUE (),
table1[Category] in ("hair-color","hair-care","hair-style"), "LUXE",
"Other"
)

 

But if need to search then you need use search, check

https://youtu.be/mZt0HJw4gjQ

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi Amit, 

 

It is throwing an error of Operator or expressions '()' is not suported in this context. 

 

Below ways can however work:

 

NEW_FIELD = SWITCH (
TRUE (),
CONTAINSSTRING(Table1[Category],"hair-color"), "LUXE",
CONTAINSSTRING(Table1[Category],"hair-care"),"LUXE",
CONTAINSSTRING(Table1[Category],"hair-style"), "LUXE"
)

 

and 

 

NEW_FIELD = SWITCH (
TRUE (),
CONTAINSSTRING(Table1[Category],"hair-color")||CONTAINSSTRING(Table1[Category],"hair-care")||
CONTAINSSTRING(Table1[Category],"hair-style"), "LUXE"
)

But I would want to see , if we can give multiple values in "IN" Statement so to avoid giving column name, using CONTAINSSTRING function again and again , like it works in Tableau by using "|" symbol and dont need to give column name repeatedly WHEN REGEXP_MATCH(Field 1, "*.Hair-Color.*|*.Hair-Care.*|.*Hair-Style.*") THEN "Hair"

Hi @Anonymous ,

 

You can use Amit's answer, but you need to use curly braces (not standard paretheses) around the 'IN' list, as it is a list. Amit's calculation updated would look like this:

New field =
SWITCH (
  TRUE (),
  table1[Category] IN {"hair-color", "hair-care", "hair-style"}, "LUXE",
  table1[Category] IN {"Skin-Sun", "Skin-Face", "Skin-Body"}, "SKIN",
  "Other"
)

 

I already suggested the CONTAINSSTRING option but Amit's method, correctly implemented, is far more performant I believe.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.