Search code examples
powerquerym

Count occurances of multiple text strings


I am looking to tell if a text is present in a text string, however I am looking to test multiple texts. For example trying to find if dog OR lazy are present in

"The quick brown fox jumps over the lazy dog and the lazy dog doesn't notice"

Tried let String = "The quick brown fox jumps over the lazy dog and the lazy dog doesn't notice,", Count = List.Count(Text.Split(String,"dog","lazy"))-1 in Count

from this article Is there a simple way to count occurences of one text string within another text string?

If dog OR lazy are present in

"The quick brown fox jumps over the lazy dog and the lazy dog doesn't notice"

Would expect yes or 1


Solution

  • Text.Split does not take two arguments

    See https://learn.microsoft.com/en-us/powerquery-m/text-split

    Try instead

    Count = List.Count(Text.Split(String,"dog")) + List.Count(Text.Split(String,"lazy"))-2