Forum Discussion

adamsharma's avatar
adamsharma
Frequent Visitor
4 years ago
Solved

Find String Containing All Words in Another String

Hi there,   Driving myself to distraction trying to figure this out so would appreciate some help.   My situation is I have two tables which contain columns with strings. I want to take the value...
  • AlexisOlson's avatar
    AlexisOlson
    4 years ago

    I think I've got it. Try substituting in this expression:

     

    if  List.Count(
            List.Select(
                Table2[string],
                each List.Accumulate(
                        Text.Split(Text.Lower(_), " "),
                        Text.Split(Text.Lower(row[string]), " "),
                        (s, c) => if s <> {} and c = s{0}
                                  then List.Skip(s)
                                  else s
                     ) = {}
            )
        ) > 0
    then "Y"
    else "N"

     

    The logic here is that it iterates through the Table2 string word by word deleting the first word of the Table1 string if it matches that word. Any Table1 string that gets entirely deleted by this iterative process is one that has all the matches in the right order.