Brian Dunning's FileMaker Custom Functions

PatternCountValues ( haystack ; needles )

Does a pattern count for multiple values at once, counting the number of times values in the second value list appear in the first value list.

  Be the first to rate this function Log in to vote

Richard Dyce   Richard Dyce - Show more from this author
Dyce & Sons Ltd.
http://dyce.com

Share on Facebook Share on Twitter

  Sample input:
PatternCountValues ( "123¶133¶234¶123¶235¶234" ; "123¶234" )
  Sample output:
4

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

There is one gotcha with this function. For backwards compatibility, I haven't included a UniqueValues ( ) check on the needles value list - which means that duplicate values in needles leads to double counting, i.e. PatternCountValues ( "123¶234¶235" ; "123¶123¶234" ) will give the answer 3. For 16 & 17 users, use:

// PatternCountValues ( haystack ; needles )

Let (
[
searchterms = ValueCount ( needles );
needles = UniqueValues ( needles ) // prevents double counting
];
Case (
haystack = "" ; 0 ;
searchterms = 0 ; 0 ;
searchterms = 1 ; PatternCount( haystack ; needles ) ;
Evaluate(
"patterncount( " &
Quote ( haystack ) & "; \"" &
Substitute (
needles ;
¶ ;
"\" ) + patterncount( " & Quote ( haystack ) & " ; \""
) &
"\" )"
)
)
)

 

Comments

Fabrice Nordmann   Fabrice Nordmann, 1-more-thing
Jan 27, 2019
how about:
ValueCount ( Filtervalues ( listA ; listB ))
 
Richard Dyce   Richard Dyce, Dyce & Sons Ltd.
Jan 28, 2019
Much better ;-)
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. 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 20 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: