Search code examples
stringsearchpowerbidaxcontains

How to search for String in Unrelated Table using DAX in Power BI?


I have a very simple problem and I'm sorry if it's been asked elsewhere but I've done a good amount of searching.

Lets say I have a column Table1[Words]:

+---------+
|  Words  |
+=========+
|   Yes   |
+---------+
|   No    |
+---------+
|  Hello  |
+---------+

Then I have an unrelated table with the column Table2[Text]:

+------------------+
|       Text       |
+==================+
|   bla bla bla    |
+------------------+
|   bla bla No     |
+------------------+
|   bla bla bla    |
+------------------+

I want to create a calculated column to show if my words from Table1 are found anywhere in the Text column in Table2. Result would be:

+---------+--------+
|  Words  | InText |
+=========+========+
|   Yes   |  False |
+---------+--------+
|   No    |  True  |
+---------+--------+
|  Hello  |  False |
+---------+--------+

Solution

  • you can do this with the find function. I made it so it counts the rows where the word is found, you can translate it to true or false.. Add a column to Table1 and paste the code below:

    WCount = 
    var findW = 'Table1'[Words]
    return CALCULATE(COUNTROWS(Table2), FILTER(Table2, FIND(findW, Table2[Text], 1, 0) >0))