Brian Dunning's FileMaker Custom Functions

SortValues ( list ; sortAscending )

Sorts the values in a list ascending or descending

  Average rating: 3.8 (39 votes) Log in to vote

Theo Ros   Theo Ros
n/a
n/a

Share on Facebook Share on Twitter

  Sample input:
SortValues ( "apple¶grape¶banana" ; True )

SortValues ( "apple¶grape¶banana" ; False )
  Sample output:
apple¶banana¶grape

grape¶banana¶apple

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

Returns the list with items sorted

Syntax: SortValues ( list ; sortAscending )
In: list - the return delimited list to search
sortAscending - if True (1), the list will be sorted Ascending,
if False (0), the sorting is Descending

Return type: Text

SortValues ( "apple¶grape¶banana" ; True ) --> "apple¶banana¶grape"
SortValues ( "apple¶grape¶banana" ; False ) --> "grape¶banana¶apple"

This sort uses functions MinValue() and MaxValue()

 

Comments

David   David, Sydney
Apr 2, 2009
"List" is now a built in function so the "list" parameter needs to be edited and given a different name.

The same applies to MinValue and MaxValue custom functions.

Thanks for the work though. It solved mt little problem!!
 
Vaughan   Vaughan, Sydney, Australia
Aug 22, 2011
/* --------------------------------------------------------------------------------
Returns the list with items sorted

Syntax: SortValues ( lst ; sortAscending )
In: lst - the return delimited list to search
sortAscending - if True (1), the list will be sorted Ascending,
if False (0), the sorting is Descending

Return type: Text

SortValues ( "apple¶grape¶banana" ; True ) --> "apple¶banana¶grape"
SortValues ( "apple¶grape¶banana" ; False ) --> "grape¶banana¶apple"

This sort uses functions MinValue() and MaxValue()

Theo Ros
-------------------------------------------------------------------------------- */

If ( ValueCount ( lst ) ;
// first make sure that the lowest or highest value and the list itself end with return
Let ( [ val = If ( sortAscending ; MinValue ( lst; "" ) ; MaxValue ( lst ; "" ) ) & "¶" ;
lst = If ( Right ( lst ; 1 ) <> "¶" ; lst & "¶" ; lst ) ;
// find and replace just 1 occurrence of the found value
rest = Replace ( lst ; Position ( lst ; val ; 1 ; 1) ; Length ( val ) ; "" ) ] ;
// finally remove any leading or trailing returns from the list
LeftWords ( val & SortValues ( rest ; sortAscending ) ; 999999999 )
)
)
 
YK   YK, JAPAN
Mar 14, 2016
Thank you. I could learn a lot from scripts in this site.
In this custom function, the last parentheses disappeared.
LeftWords ( "XXXX(xxxx)" ; 999999999 ) = "XXXX(xxxx"
 
Danny R   Danny R, western Washington
Jan 23, 2018
Tried to use this to reverse a value list. Keeps telling me to add +,-,; etc. characters after "MinValue" Am I doing something wrong?
 
Danny R   Danny R, western Washington
Jan 23, 2018
nm. Figured it out.
 

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.

Under construction. Email me your wish list for improvements.