Shopping Cart

Search:

Signup

Contact

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

# FileMaker Pro Custom Functions

ValuePosition ( valuelist ; searchvalue )

Rate this function:

Discuss this Custom Function

Michael Bijnens, freelance developer
/

Get position number of the search value from the value list

Sample Input:
 ValuePosition ( a¶b¶c¶d¶e¶f" ; "d" )
Sample Output:
 4

Then copy & paste into FileMaker Advanced's Edit Custom Function window.

## Description:

This CF gives you the position number of the search value from the given value list ( array separated by ¶ ).

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

This is my Custom Function and I want to edit it

## Discuss:

ValuePosition ( "a¶b¶c¶b¶a" ; "a" ) = 5; and ValuePosition ( "a¶b¶c¶b¶a" ; "b¶c" ) returns empty!?

But then it's not necessary to employ a recursive mechanism for finding the index of the first occurrence; simply use

ValueCount ( Left ( valuelist ; Position ( valuelist ; searchvalue ; 1 ; 1 ) ) )

btw. …

found = Case ( lastvalue = search ; True ; False )

is the same as

found = lastvalue = search

and

exist = Case ( PatternCount ( list ; search ) = False and not IsEmpty ( search ) ; False ; True )

is simply

exist = PatternCount ( list ; search )

Oliver, Tegernsee
June 03, 2014 5:11am

Dear Oliver,

As you can see my CF name = ValuePosition and not ValuePositionS.
So its not made for more multi value searches.

Try your simple example with numbers like ( 53 , 353, 121, 12 ).

I have tried it in many different ways but it is not waterproof so thats why I use a recursive function.

Michael Bijnens, Belgium
June 04, 2014 12:49am

Michael wrote:
Try your simple example with numbers like ( 53 , 353, 121, 12 )

Michael –

you're right, I forgot a little detail; change it to

ValueCount ( Left ( valuelist ; Position ( ¶ & valuelist & ¶ ; ¶ & searchvalue & ¶ ; 1 ; 1 ) ) )

and that'll give you exactly the same functionality without recursion.

Also, note that your CF returns the last position, not the first one.

Oliver, Tegernsee
June 04, 2014 2:36am

// I like to use this:

/*
ValuePosition( _valuelist; _value )

Parameters:
_valuelist: a return-delimited string of values;
_value: a single-line string.

Returns:
an integer identifying the listed position of (the first occurrence of) _value within _valuelist,
or 0, whenever the _value is not listed.
*/

If(
// return zero when no match occurs:
IsEmpty( FilterValues( _valuelist; _value ) ); 0;

// FileMaker 15 should provide something like this function for us, but doesn't …
Let(
[
// first, bracket the arguments supplied with "¶"s:
_valuelist = "¶"&_valuelist&"¶";
_value = "¶"&_value&"¶";

// locate the "¶" character immediately preceding (the first occurrence of) _value:
_position = Position( _valuelist; _value; 1; 1 );

// extract all the return characters BEFORE this _position:
_returns = Filter( Left( _valuelist; _position ); "¶" );

// how many are there?
_valuePosition = Length( _returns )
];

_valuePosition
)
)

Late to the party, Shanghai
January 08, 2016 2:29am

valuePosition ( "AB¶BC¶CD","B" ) returns an out-of-memory error due to runaway recursion.

Michael Kupietz, United States
November 18, 2017 7:10pm