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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
maalsan
Frequent Visitor

Find multiple substring DAX CONTAINSSTRING

Hello everyone,

 

I need to find if the substrings "house", "home", "dewelling" appear in a long string column. Using CONTAINSSTRING I am able to find each word at a time- house= CONTAINSSTRING(table1[column1], "house"). Is there a way to look for more than one substring? Perhaps something like house= CONTAINSSTRING(table1[column1], "house" or "home" or "dewelling").

 

Thank you for any help!

1 ACCEPTED SOLUTION

That's weird. It still gives me an error message. 

I found the solution to be simply:

house= CONTAINSSTRING(table1[column1], "house" ) || CONTAINSSTRING(table1[column1], "home" ) || CONTAINSSTRING(table1[column1], "dewelling" )

 Without the need of IF statements. 

 

Thanks!

View solution in original post

12 REPLIES 12
RajaCSN
Helper III
Helper III

Hi maalsan,

 

Assuming that you have table called "String" where Description is your column header; You have another table called Keyword, that contains a column header Keyword.

 

RajaCSN_0-1645766204475.png

You can load both the tables to PowerBI and then for the String Table, you can create a calculated column as below:

 

RajaCSN_1-1645766425807.png

 

Is this providing a solution for your query? If "yes" kindly confirm.

 

Request other experienced users to add value to my suggestion.

 

Best Regards,

 

C.S.N. Raja

 

 

Thanks !

Hi Raja, im fascinated by your solution. Nevertheless I cant recreate it for myself.
The Search Process works fine, but my Result (when found) gives always ALL values from the Keyword list back.

The rootcause seems to be the "ResultwhenTrue" of the If statement.


EDIT: My Colleague found the problem. You cant have a active relation between the two tables. -.- 

Awesome.

Hi @RajaCSN,
I found your solution very helful, honestly speaking it's mindblowing!
Trying to adjust it to my needs, if I put Keyword column in a slicer giving user option to select one or multiple values. How to adjust DAX so it's still working?
Curent solution is taking all values no meter what is selected in slicer.

Yes, that is a limitation. Let me check if your requirement can be done by me or else we can seek assistance from other experienced users in this community.

Thanks @RajaCSN ,
Initialy it sould like simple request, but so many colequest I reached were not able to assist.

 

Brilliant scaleable solution. This way you only need to edit your keyword list and it will automatically update.

Greg_Deckler
Super User
Super User

@maalsan Try:

house = 
  IF(
    CONTAINSSTRING(table1[column1], "house") ||
    CONTAINSSTRING(table1[column1], "home") ||
    CONTAINSSTRING(table1[column1], "dwelling"),
    TRUE(),
    FALSE()
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thanks for the reply. However, it seems that containsstring function only allowes for 2 arguments max. I got the following error message: "Too many arguments were passed to the CONTAINSSTRING function. The maximum argument count for the function is 2".

@maalsan This worked for me:

Greg_Deckler_0-1645743543670.png

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

That's weird. It still gives me an error message. 

I found the solution to be simply:

house= CONTAINSSTRING(table1[column1], "house" ) || CONTAINSSTRING(table1[column1], "home" ) || CONTAINSSTRING(table1[column1], "dewelling" )

 Without the need of IF statements. 

 

Thanks!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.

Top Solution Authors