Brian Dunning's FileMaker Custom Functions

CountWordOccurrences ( text ; searchWord )

Returns the number of occurrences of searchWord as word in text.

  Average rating: 4.9 (34 votes) Log in to vote

Michael Horak   Michael Horak - Show more from this author
*COMMENT Visual Realisation

Share on Facebook Share on Twitter

  Sample input:
CountWordOccurrences ( "Ground control to Major Tom, ground control to Major Tom: can you hear me, Major Tom?" ; "tom" )

CountWordOccurrences ( "Tom stomped on an atom." ; "tom" )

CountWordOccurrences ( "Tom's tomcat stomped on an atom." ; "tom" )
  Sample output:



  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Returns the number of occurrences searchWord appears as a word in text. The function is NOT case-sensitive.



Henk Brendel   Henk Brendel, Arnhem, NL
Feb 8, 2012
PatternCount ( text ; " " & Trim ( searchWord ) & " " )

Isn't this simpler, doing the same thing and at least not recursive?
comment   comment, VR
Feb 8, 2012
It may be simpler, but it's not doing the same thing at all: check your results against mine in the examples above.
Henk Brendel   Henk Brendel, Arnhem, NL
Feb 8, 2012
I see what you mean, sorry about this.
Danton Wetzel   Danton Wetzel, Saint George, UT
Sep 10, 2013
This is exaclty what I need, but FileMaker 11 gives me an error. "This function cannot be found."
I believe it is refering to "Let ( countWords = WordCount ( text )".

Can you help me understand, please.

Thanks in advance.
jLT StructuresFromSilence   jLT StructuresFromSilence, Kendv,IN USA
Apr 8, 2015
Like this function much but problems with it.


You ever get this custom function to work properly?


When i use it in a text field that is lengthy i get a spinning ball and have to wait long time!!
comment   comment, VR
Apr 8, 2015

This function goes over your text word-by-word. That takes some time. It was not meant to be applied to large texts, and in any case the maximum amount of words it can process is limited to 10,000 (Filemaker's limit of iterations for custom functions that are not tail-recursive).

You may consider implementing the same algorithm in a looping script, and run the script on demand only, storing the result in a field.

Log in to post comments.


Note: these functions are not guaranteed or supported by Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 16 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: