Select closest date to a month ago

m9m9m9m

New Member
Joined
Aug 1, 2012
Messages
11
Hi all,

Any idea how I can select the closest date to a 30 days ago ? Vlookup & Co only deliver the largest date that is smaller then the selection, not necessarily the closest. Here is an example:

Col A Col B Col C
"DATE" "DATA" "Last 30 day Average of Data"
25/10/2009 5 "formula to calculate the average of the last 30 days"<formula to="" calculate="" average="" of="" last="" 30="" days="" until="" date="">
26/11/2012 6 <formula to="" calculate="" average="" of="" last="" 30="" days="" until="" date="">"formula to calculate the average of the last 30 days"
25/12/2012 7 <formula to="" calculate="" average="" of="" last="" 30="" days="" until="" date="">"formula to calculate the average of the last 30 days"

Match and Vlookup in C5 will look at the 2009 date but of course 26/11/2012 is much closer to -30 days than the 2009 date.
I have written a macro to solve this - but I'd like a formula in Col C. It should not be an array formula as this formula has to work on about 300 rows in Col C.
I found this - which is an array, hence not tested:

=INDEX(Datelist, MATCH(MIN(ABS(Datelist-A1)), ABS(Datelist-A1), 0))

The date list is sorted by date.
Any help would be very much appreciated.</formula></formula></formula>
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
fyi: The Macro basically goes back to find a date that is smaller that A5-30days then checks if the next entry is closer to 30 days (i.e. chooses the smallest value for date-30 from the 2 candidates)
 
Upvote 0
Not sure if I understand the question, but this one calculates the average of the last 30 days
based on the date in A column.
=AVERAGEIFS($C$2:$C$100,$B$2:$B$100,"<="&B2,$B$2:$B$100,">"&(B2-30))
Change the range to your needs. Paste it in C2 and copy down.

Vidar
 
Upvote 0
Your Dates A2:a24 on Sheet3
In E1:
=TODAY()-30
Named Range:
=ABS(Sheet3!$A$2:$A$24-Sheet3!$E$1)=MIN(ABS(Sheet3!$C$2:$C$24-Sheet3!$E$1))
Formula
=INDEX($A$2:$A$24,MATCH(TRUE,dates,ROWS($1:1)-1))
 
Upvote 0
Thanks Vidar and Robert for your quick response.
Unfortunately none of the suggested methods worked for me, although I didn't quite understand your method Robert.

Here is the workaround I have at the moment, which does not really work as it chooses the wrong line (hope this copy and paste works):

cell A1DateReadingAverage of last 30 days based on current readingComment
cell A215-Feb 00:0012447.0000#N/A
cell A310-Apr 09:4712522.748541.70
cell A418-Apr 12:0912533.142841.37
cell A518-May 12:3012565.689433.07
cell A627-Jun 08:4412597.916024.67
cell A721-Jul 21:5312616.865024.24
cell A826-Jul 21:5312626.865026.89this row is currently using the 18-May data but should be using the 27-June Data since 27-June is closer to "a month ago" than 18-May
cell A9
cell A10formula in D8: '=(C8-VLOOKUP(B8-30,B$2:C8,2))/(B8-VLOOKUP(B8-30,B$2:C8,1))*30.5
cell A11simplified formula in D8: =(C8-C5)/(B8-B5)*30.5

<tbody>
</tbody>
 
Last edited:
Upvote 0
cell A12simplified should be formula in D8: '=(C8-C6)/(B8-B6)*30.5

<tbody>
</tbody>

I hope this makes a little more sense of what I am trying to achieve.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,346
Members
449,155
Latest member
ravioli44

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