Brian Dunning's FileMaker Custom Functions

Median ( valueList )

returns median value of a value list

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

Daniele Raybaudi   Daniele Raybaudi
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, Toronto
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.

Under construction. Email me your wish list for improvements.