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

Working with Lotus 1-2-3 Spreadsheets

If you've got some older data around your office that started in an old Lotus 1-2-3 system, you may want to open it in Excel. ...

Discover More

Hiding Spelling Errors

When you are typing in a document, Word normally checks your spelling in the background, marking possible spelling errors as ...

Discover More

Sorting Letters and Numbers

Sorting information in a worksheet can be confusing when Excel applies sorting rules of which you are unaware. This is ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Counting the Number of Blank Cells

If you need to count the number of blank cells in a range, the function to use is COUNTBLANK. This tip discusses the ...

Discover More

Establishing a FLOOR and CEILING

Excel includes a surprising number of functions you can use to round your data. Two such functions are FLOOR and CEILING, ...

Discover More

Using the EOMONTH Function

If you need to determine the date of the last day in a month, it's hard to beat the flexibility of the EOMONTH function. This ...

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 8Mpixels. 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 0 + 7?

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.