This AppleWorks add-on function allows a spreadsheet to calculate the statistical median of a set of data.



This is one of over 40 features in the Enhancement Pack for AppleWorks.


The “Median” custom function does not appear in the Scripts menu. You invoke it by using the “MACRO” function in a spreadsheet cell or calculated field. The easiest way to do this is to use the “Function...” menu item in the Scripts menu. It copies the syntax:

MACRO("Median",2,"calculate", data)

You paste this into a spreadsheet cell after an “=” (equals) sign, then replace the parameter “data” with a range of cells.

To view this sample included with the Enhancement Pack, open the document:

AppleWorks/ AppleWorks Essentials/ Scripts Support/ Documentation/ Script Function Samples.cwk

The example explains how the above sample was constructed.

    1. In a spreadsheet, enter your raw data, such as I the sample data in cells B17 through B24:

    2. In the cell where you want the calculation (I used cell E18 in the sample document), type an equals sign and leave the cursor flashing.

    3. Select the "Function..." command from the Scripts menu, select "Median" from the list.

    4. Paste (from the Edit menu) the function into your formula, so it reads:
                     =MACRO("Median",2,"calculate", data)

    5. Select the "data" parameter in your formula and drag a selection over the cells containing your data. For instance, if your data was entered into cells B2 to B8, then the formula would now appear as:

                     =MACRO("Median",2,"calculate", B2..B8)

    6. Hit the Enter key. Your calculation should update, as shown in the sample document:

Because the functions are dynamically calculated, you can change the precedent data points to see the median update automatically.

The “Median” function can be placed in any spreadsheet cell.

This script works with AppleWorks 6 and AppleWorks 5.

Only registered users are permitted to use the supplied files after 14 days or edit them.

This script is included in the Enhancement Pack for AppleWorks, not supplied separately.

To make the script editable, drag and drop it onto the “Show/Hide in Scripts Menu” applet in the Scripts Support folder, then double click to open in your script editor. After closing the script, drop it on the applet again to hide it in the AppleWorks menu.

Here’s an extract from the script:

on calculate(theCells)
   set rawList to theCells

   set cellCount to count of rawList
   set sortedList to anyLib's SortList(rawList)
   set theMedian to item (1 + cellCount div 2) of sortedList
   if cellCount mod 2 = 0 then -- even number of cells
      set theMedian to (theMedian + (item (cellCount div 2) of sortedList)) / 2
   end if

   return theMedian
end calculate

Please email us any queries about this page.