Brian Dunning's FileMaker Custom Functions

Median ( valueList )

returns median value of a value list

  Average rating: 4.0 (40 votes) Log in to vote

Daniele Raybaudi   Daniele Raybaudi - Show more from this author
ACI
http://www.aci.it

Share on Facebook Share on Twitter

  Sample input:
0
2
3
5
6
8
9
  Sample output:
5

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

Returns median value of a value list.
ValueList must be sorted in ascending order.

 

Comments

David Weaver   David Weaver, Australia
Jun 30, 2010
You need to use MiddleValues with this function rather than MiddleWords. MiddleWords removes decimal points for non integer values.

Let ([
count = WordCount ( valueList ) ;
odd = MiddleValues ( valueList ; Truncate (count/2;0) +1 ; 1 );
even = MiddleValues ( valueList ; Truncate(count/2;0) ; 1 )
];
Case(
Mod ( count ; 2 ) ; odd ; (even+ odd) / 2
)
)
 
Brian Panhuyzen   Brian Panhuyzen, Neutrino Data Systems
Nov 24, 2016
Important to note in the description: "ValueList must be sorted in ascending order." I use the revised version that replaces MiddleWords with MiddleValues, and I use one of the other sort functions on this site as the first item in the Let statement to first sort valuelist , so:

Let ([
valuelist = SortValues (valuelist; 1);
count = WordCount ( valueList ) ;
odd = MiddleValues ( valueList ; Truncate (count/2;0) +1 ; 1 );
even = MiddleValues ( valueList ; Truncate(count/2;0) ; 1 )
];
Case(
Mod ( count ; 2 ) ; odd ; (even+ odd) / 2
)
)
 

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: