Forum Discussion

GDemnerIMUK's avatar
GDemnerIMUK
Regular Visitor
7 years ago
Solved

Check string for values in other table

Hey guys, 

 

I have a list of social media posts about companies and i want to categorise which company this is. 

 

I have a list of all the potential companies that could be there and i want to search the subject string to see if it contains one of the values in this table. 

 

I then want to return the value it found. 

 

Is there a good way to do this? 

 

Thanks, 

George 

  • ImkeF's avatar
    ImkeF
    7 years ago

    Say you have your posts in a table, then you can add a column with this formula:

     

    List.First(List.Select(ListOfPotentialCompanies, (x) => Text.Contains([Post], x))) 

    You can also paste this code into the advanced editor to see how this works:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kjMyclX8M1MLsovzk8rUYrViVbyVMjJL0tVCMgvTy1ScPJUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Post = _t]),
        ListOfPotentialCompanies = {"Microsoft"},
        #"Added Custom" = Table.AddColumn(Source, "Custom", each List.First(List.Select(ListOfPotentialCompanies, (x) => Text.Contains([Post], x))))
    in
        #"Added Custom" 

    As you'll see, only the first value from the possible list of matches is selected, but you can omit that part of the formula if you want to retrieve all matches instead.

8 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Hmmm, maybe if you could somehow split out the text into a table and then use GENERATE against this table and your other table along with maybe an ADDCOLUMN or something. Sounds nasty and computational expensive in DAX.

     

    Or are you looking for a Power Query solution?

    • GDemnerIMUK's avatar
      GDemnerIMUK
      Regular Visitor

      Hey, 
      Ideally looking for a solution in power query. The idea is that when these have been categorised i can then slice all the data from one slicer :-)