Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Median of Selected Numbers.

Median of Selected Numbers

by Allen Wyatt
(last updated April 14, 2016)

6

William is trying to find the median of about 3,000 numbers in a column that has a range from 0.9 to 5. However, he only wants the median of numbers that are greater than 1. He can't figure out how to put that parameter into his formula and is looking for ideas.

Short of creating a user-defined function in a macro, there are a couple of ways you can go about determining the median. One method is to use an intermediate column that contains only those values above 1 and then calculate the median based on those values. You could also use an advanced filter to extract only the values above 1 and then use those values to find the median.

A better approach, however, is to use a simple array formula:

=MEDIAN(IF($A$1:$A$3000>1,A1:A3000))

When you enter this as an array formula (by using Ctrl+Shift+Enter), the result is your median value, with your criteria taken into account.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7922) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Median of Selected Numbers.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Headers and Footers in Subdocuments

If you use master and subdocuments, you may wonder how to control headers and footers in the subdocuments. This tip shares ...

Discover More

Automatically Determining a Due Date

When you are doing a mail merge in Word, you may need to calculate a date sometime in the future. Word doesn't include an ...

Discover More

Automatic Selection of Portrait or Landscape

Should you print in portrait or in landscape? The decision can greatly affect the way your printout looks. Wouldn't it be ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Making VLOOKUP Trigger a Macro

VLOOKUP is an oft-used worksheet function to lookup values in a data table. If the function cannot return a value, it ...

Discover More

Determining Columns in a Range

If you need to know the number of columns in a particular range, you can use the COLUMNS worksheet function. This tip ...

Discover More

Specifying Proper Case

If you need to change the case of letters in a cell, one of the functions you can use is the PROPER function. This tip ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 2?

2016-04-14 10:47:16

Dave Bonin

I avoid array formulas like the plague.

Why? Because they are so easily broken by other users who don't know to Ctrl+Shift+Enter and by me when I forget to.

Instead, I use the SUMPRODUCT function. It generally works the same and I don't need Ctrl+Shift+Enter.

Here are two examples:

= SUMPRODUCT (( A1:A10 > 3 ) * ( B1:B10 < 5 ), D1:D10 )

= SUMPRODUCT ( - - ( A1:A10 > 3 ), D1:D10 )

In the first example, we have two arrays of logical conditions. Each gives us an array True's and False's. When the two arrays are multiplied together, they produce an array of 1's and 0's, which SUMPRODUCT then multiplies by the array in column D. This method works with two or more conditional arrays.

In the second example, we only have one array of logical conditions. It gives us one array of True's and False's. SUMPRODUCT does not like working directly with True's and False's, so we use double negation to turn them into 1's and 0's.

Using double-negation, the first example can be re-written as:

= SUMPRODUCT ( - - ( A1:A10 > 3 ), - - ( B1:B10 < 5 ), D1:D10 )

SUMPRODUCT can also be used with logical functions like OR and AND.

PS: Double negation is a great way to turn True's and False's into numeric values for calculations.

PPS: You will notice that my formula examples included spaces. I always use spaces for readability and I have no idea why everyone doesn't. When we write an email or a letter, we all use spaces to separate the words and make them more readable. Why do so few do use spaces in formulas?


2016-04-14 08:02:16

Another Joe

Joe, Ed,
Boolean operations (AND, OR etc) don't work with array formulae. More information is given here :
http://dailydoseofexcel.com/archives/2004/12/04/logical-operations-in-array-formulas/


2015-10-14 06:18:50

Joe

Not sure why that did not work. I got it to work with this though:

{=MEDIAN(IF((DATE(YEAR(ListDate),MONTH(ListDate),1)=$A3)*(SellerType="Fresh"),Price))}


2015-10-14 06:13:11

Joe

Thanks Ed, I'll give it a try


2015-10-12 10:53:55

Ed


Try using "AND" instead of nesting the two "IF" functions. I didn't test it, but this is what I came up with:

{=MEDIAN(IF(AND(DATE(YEAR(ListDate),MONTH(ListDate),1)=$A3,SellerType="Fresh"),Price))}


2015-03-11 06:46:21

Joe

How can you make this work for multiple conditions? I have a database of home sales and have defined "ListDate" as the range of dates properties were listed, and "Price" as the price at which they were listed for sale.
In column A, I have months, ie Oct-14, Nov-14, Dec-14 ... and I then want to use an array formula to calculate the median price. The following formula works perfectly.
{=MEDIAN(IF(DATE(YEAR(ListDate),MONTH(ListDate),1)=$A3,Price))}
But then I have another field where I have defined two types of property sellers "SellerType" and I want to only generate the median home price each month for "Fresh" seller types. The following array generated "#N/A" .... help?
{=MEDIAN(IF(DATE(YEAR(ListDate),MONTH(ListDate),1)=$A3,IF(SellerType="Fresh",Price)))}


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.