Question

Unfortunately I have to do this in Excel.

I need to find the most recent date for each ID code, within a range of two dates. I can do each bit separately, but I cannot seem to put them together to get what I need.

For the following example data:

a   21/11/2012
b   17/12/2014
a   08/01/2013
b   03/12/2012
c   04/12/2012
c   05/12/2012
c   06/12/2013

If I am looking for the latest response between the 2012-13 academic year - 31/08/2012 to 1/9/2013 I would like to get the following result:

a   08/01/2013
b   03/12/2012
c   05/12/2012

I used the following array formula to get the latest date regardless of year:

{=MAX(IF($A$1:$A$7="a",$B$1:$B$7))}

And I used the following formula to get a date for within the academic year:

=IF(COUNTIFS($B$1:$B$7,">="&$F$10,$B$1:$B$7,"<="&$G$10,$A$1:$A$7,"="&"a")>0,B1:B7,"")

(where F10 is 31/8/12 and G10 is 1/9/13)

I tried this... it didn't work:

{=IF(COUNTIFS($B$1:$B$7,">="&$F$10,$B$1:$B$7,"="&$G$10,$A$1:$A$7,"="&$E1)>0,MAX(IF($A$1:$A$7=E1,$B$1:$B$7)),"")}

I can't simply sort the column by decreasing date so the date it comes across first is the latest, because I also need to a similar thing for another column, and they aren't always in the same order.

Many thanks for any help!

Was it helpful?

Solution

you were close with this:

{=MAX(IF($A$1:$A$7="a",$B$1:$B$7))}

You need to filter out the dates that don't match your criteria, which can be done with this:

IF($B$1:$B$7<=date(2013,9,1), ...
IF($B$1:$B$7>=date(2012,8,31), ...

You can't join them using AND, as it will convert the array to a single value

{=MAX(IF(AND($A$1:$A$7="a",
             $B$1:$B$7<=date(2013,9,1),
             $B$1:$B$7>=date(2012,8,31)
             ),$B$1:$B$7))}

will return either the 1st item in the B1:B7 range, or 0, depending on how all the tests went. So the next step is to daisy chain the IF's together, which gives you this:

{=MAX(IF($A$1:$A$7="a",
          IF($B$1:$B$7<=$G$10,
              IF(B1:B7>=$F$10,$B$1:$B$7))))}

(spread out so you can see the nesting of the IF statements) Which will now give you the result you want: 8/1/2013

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top