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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
matheus_peppers
Frequent Visitor

How to use CONTAINSTRING inside SWITCH?

Hello everybody, how are you?

 

I need your help urgently for a problem I'm having.

 

I have a column with different values, but with a specific string that repeats in more than one row.

 

What do I need to do?

 

I need to categorize these specific strings into 3 different categories, which are the regions that each location equals.

 

I am trying to use SWITCH with CONTAINSSTRING, because I need it to return the text I want in the calculated column if it finds the text I am looking for.

 

But it is not working. Can anyone help me and tell me where I am going wrong, or any alternative way for me to get what I want?

 

Screenshot_133.png

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @matheus_peppers ,

Here are the steps you can follow:

1. Create calculated column.

Column =
SWITCH(
    TRUE(),
CONTAINSSTRING('Table'[Anuncio],"Taubate")=TRUE(),"Taubate",
CONTAINSSTRING('Table'[Anuncio],"Canas")=TRUE(),"Canas")

2. Result:

vyangliumsft_0-1664341111418.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @matheus_peppers ,

Here are the steps you can follow:

1. Create calculated column.

Column =
SWITCH(
    TRUE(),
CONTAINSSTRING('Table'[Anuncio],"Taubate")=TRUE(),"Taubate",
CONTAINSSTRING('Table'[Anuncio],"Canas")=TRUE(),"Canas")

2. Result:

vyangliumsft_0-1664341111418.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@matheus_peppers , You should use Switch (True(),

and then you can check for true in each expression

 

Switch-Case statement of #PowerBI: https://www.youtube.com/watch?v=gelJWktlR80&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=56

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.