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

Vertically Centering Labels

Want the text printed on your labels to be centered vertically? It's not that hard, and this tip shows the easiest method.

Discover More

Scaling Graphics in a Macro

If you need to make sure that the graphics in a document are all scaled similarly, you'll love the macros presented in this ...

Discover More

Problem with Missing Context Menu Option

When you right-click a cell, does it seem that the Context menu is missing an item or two? Here's how to get those items ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Converting Radians to Degrees

When applying trigonometry to the values in a worksheet, you may need to convert radians to degrees. This is done by using ...

Discover More

Converting to Octal

If you need to do some work in the base-8 numbering system (octal), you'll love two worksheet functions provided by Excel for ...

Discover More

Rounding to the Nearest $50

When preparing financial reports, it may make your data easier to understand if you round it to the nearest multiple, such as ...

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. 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 six less than 6?

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.