Excel: Finding the Median of a Sorted Series of Numbers

Last reviewed: November 2, 1994
Article ID: Q64339

SUMMARY

Note: The following article pertains only to versions of Microsoft Excel previous to version 3.00. Excel 3.00 introduced the MEDIAN function. For more information on MEDIAN, see page 150 in the "Microsoft Excel Function Reference" version 3.0 manual.

To compute the median of a sorted series of numbers in Excel, use the following formula

   =IF(MOD(COUNT(range),2)<>0,INDEX(range,INT(COUNT(range)/2)+1,1),
   (INDEX(range,COUNT(range)/2,1)+INDEX(range,(COUNT(range)/2)+1,1))/2)

where "range" is the array of cells that contain the series of numbers. For example, if the series of numbers were located in cells A1 through A10, then A1:A10 would be entered as the range in the above formula.

Note: The series of numbers must be sorted for this formula to work.

The median of a series of numbers is defined to be the middle number in a series with an odd number of items, or the average of the two middle numbers in a series with an even number of items. For example, consider the following series of numbers:

   1, 4, 7, 16, 43

In this case, the median is 7 because there is an odd number of items in the series, and 7 is the middle number.

In the following example

   3, 4, 8, 12, 46, 72

the median is 10 because there are an even number of items in the series. As a result, the average of the two middle numbers (8 and 12) is computed, giving a result of 10.

MORE INFORMATION

This function can also be entered into a function macro, as follows:

  1. Open a new macro sheet and type the following:

          Cell   Entry
          ----   -----
    
          A1     Median
          A2     =ARGUMENT("range",64)
          A3     =RETURN(IF(MOD(COUNT(range),2)<>0,INDEX(range,
                  INT(COUNT(range)/2)+1, 1), (INDEX(range,COUNT(range)/2,1)
                  +INDEX(range,(COUNT(range)/2)+1,1))/2))
    
    

  2. Highlight cell A1 and choose Define Name from the Formula menu. "Median" should appear in the Name box and "=$A$1" should appear in the Refers To box.

  3. Click the Function radio button to define the macro as a function macro, and click OK.

To use this function macro, do the following:

  1. With your spreadsheet active and the macro sheet open, select the spreadsheet cell in which you want to place the function. From the Formula menu, choose Paste Function and select the Median function, which should appear at the bottom of the list with the syntax "Macroname!Median". Click OK.

  2. Inside the parentheses, enter the range that you want the median to be and press RETURN.


KBCategory: kbother
KBSubcategory:

Additional reference words: noupd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.