Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Contains function - number of hits

janez_007
7 - Meteor

Hi everyone,

 

need support using the Contains function. I am doing a simple word search and would like to get the number of hits.

 

Example text:

A brown cat is in the garden for brown cats. 

 

Keyword:

brown cat

 

The contains function returns '-1' even though there are two hits in the sentence. Any suggestions?

 

4 REPLIES 4
nerces
8 - Asteroid

That's because the contains functions returns a TRUE or FALSE value. It does not return a count of the number of instances for your keyword.

janez_007
7 - Meteor

ok, understood, thank you for the reply.

thllm
7 - Meteor

Hi Janez,

 

You can find the solution for this by using the help documentation.

https://help.alteryx.com/current/Reference/Functions.htm

The contains formula returns a boolean value based on whether the text is contained in the field.

 

The function you want is probably Regex_CountMatches and looks like this.

REGEX_CountMatches([Sample_text], "brown cat")

 

janez_007
7 - Meteor

REGEX_CountMatches works perfectly, thank you for the suggestion.

Labels