Calculating Median if Passes Logic Test

JMHoustonTX

New Member
Joined
Nov 3, 2014
Messages
4
Hello, I am stumped! I need help to calculate the median value in Column B if Date in Column A is within a certain month.
For Instance:

A B
1 1/1/2014 34
2 2/5/2014 45
3 1/27/2014 15
4 1/15/2014 7
5 2/27/2014 15


The median for January would be 15.

I thought I could use this:
{=median(if(sumproduct((A:A>=datevalue("1/1/2014"))*(A:A<=datevalue("1/31/2014))),b:b)}

This returns the median for all of column B. Anyone have any ideas?

Thank you!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try...

=MEDIAN(IF(A2:A100>=DATEVALUE("1/1/2014"),IF(A2:A100<=DATEVALUE("1/31/2014"),B2:B100)))

...confirmed with CONTROL+SHIFT+ENTER. Adjust the ranges, accordingly. Try to avoid using whole column references, since array formulas such as this one are resource intensive.

Hope this helps!
 
Upvote 0
Thank you for your help!
I'm not sure what my error is but that formula isn't working for me.
The answer should be 54, and if the entire column was calculated (like with my first formula), the answer would be 42. The new formula gives me 32.. Im not sure what it is calculating =/

Any other suggestions?
Any help is much appreciated.
 
Upvote 0
First, make sure that you confirmed the formula with CONTROL+SHIFT+ENTER. If done correctly, Excel will automatically place curly braces {...} around the formula. Then make sure that the dates in Column A are true date values. You can use ISNUMBER to test for a true date value. So, for example, the following formula returns TRUE if the cell contains a true date value...

=ISNUMBER(A2)

Does this help?
 
Upvote 0
I still cant get it to work. There are empty cells in column B, do you think this could be the culprit?

Maybe I could attack this from a new angle with something like:

=MEDIAN(IF(MONTH(A2:A1500)=1,B2:B1500)) as an array.

Could that work? (It doesn't right now, haha)
 
Upvote 0
In this case, empty cells will be treated as zeros. Therefore, to ignore empty cells, try...

=MEDIAN(IF(A2:A100>=DATEVALUE("1/1/2014"),IF(A2:A100<=DATEVALUE("1/31/2014"),IF(ISNUMBER(B2:B100),B2:B100))))

...confirmed with CONTROL+SHIFT+ENTER.

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top