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

Line Numbering and Tables

Some types of documents (such as legal documents) may require that individual lines of text be numbered. If you use tables to ...

Discover More

Weighted Averages in a PivotTable

PivotTables are used to boil down huge data sets into something you can more easily understand. They are very good simple ...

Discover More

Shortening ZIP Codes

US ZIP Codes can be of two varieties: five-digits or nine-digits. Here's how to convert longer ZIP Codes to the shorter ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

MORE EXCELTIPS (RIBBON)

Returning Blanks or Asterisks from a Lookup

Want to return more than a value when doing a lookup? Here are a couple of ways to do it by adding an IF clause to your ...

Discover More

EOMONTH Function is Flakey

Some users have reported problems using the EOMONTH function in later versions of Excel, beginning with Excel 2007. The ...

Discover More

Using the WEEKNUM Function

Need to know which week of the year a particular date falls within? Excel provides the WEEKNUM function so you can easily ...

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 for this tip:

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 two more than 9?

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.

Links and Sharing