How to find the median of a dataset

Hi,

I’ve got a site which uses a big database of classic car prices within it. Is there an easy way within Wix to find the Median of the queried dataset? I can do it easily for sum, average etc but median seems to be missing in terms of a simple function.

Cheers,
Giles

If you are performing a query, then you can use the resulting array of items:

  • Sort the array of items by the field that you want the median value of.

  • Find the middle of the array - (array length / 2)

  • Return the number at the midpoint if the length of the array is odd, otherwise return the average of the two middle numbers.