Date-dependent calculations

P

paulkaye

Whew - this one has really got the better of me. I'm not used to using
dates in Excel and I just can't figure this one out by myself. Here's
what I'm trying to do:

Column A = list of months (across several years)
Column B = sales forecast for month in column A

I would like to calculate the total forecast sales for the "next 12
months" (i.e. based on the current date). Please help me!
 
R

RagDyeR

Exactly how are the months entered in Column A?
Are they text, or legal XL dates formatted to display months, or ... what?
--

Regards,

RD
-----------------------------------------------------------------------------------------------
Please keep all correspondence within the Group, so all may benefit !
-----------------------------------------------------------------------------------------------

Whew - this one has really got the better of me. I'm not used to using
dates in Excel and I just can't figure this one out by myself. Here's
what I'm trying to do:

Column A = list of months (across several years)
Column B = sales forecast for month in column A

I would like to calculate the total forecast sales for the "next 12
months" (i.e. based on the current date). Please help me!
 
B

Bernard Liengme

Assuming you want the sum to include the current month
=SUMPRODUCT(--(MONTH(A1:A30)+12*(YEAR(A1:A30)-YEAR(TODAY()))-MONTH(TODAY())>=0),--(MONTH(A1:A30)+12*(YEAR(A1:A30)-YEAR(TODAY()))-MONTH(TODAY())<12),B1:B30)

Change A1:A30 and B1:B30 to fit your needs. But SUMPRODUCT cannot use full
columns such as A:A,

For next month on (current month excluded)
=SUMPRODUCT(--(MONTH(A1:A30)+12*(YEAR(A1:A30)-YEAR(TODAY()))-MONTH(TODAY())>0),--(MONTH(A1:A30)+12*(YEAR(A1:A30)-YEAR(TODAY()))-MONTH(TODAY())<=12),B1:B30)

I had hoped to use DATEDIF but failed
best wishes
 
P

paulkaye

Hi RD,

They are 'legal' Excel dates (e.g. 01/10/07) formatted to display
months (e.g. Oct-07). I'd be happy to use anything though.

Thanks,

Paul
 
P

paulkaye

Hi Bernard,

Thanks for your reply but I can't understand what you've done or why!
Sorry - I'm a bit of a newbie. It seems like I'd have to do this for
every month, rather than it calculating based on the current month. Is
that what you meant by not being able to use DATEDIF?

Many thanks,

Paul
 
R

RagDyer

Assumptions:
Column A filled with "legal" XL dates.
Dates are in chronological order.
Headers in Row1, with datalist in A2 to B50

Try this:

=SUM(INDEX(B2:B50,MATCH(--TEXT(TODAY(),"mm-yyyy"),A2:A50)+0):
INDEX(B2:B50,MATCH(--TEXT(TODAY(),"mm-yyyy"),A2:A50)+11))

I guessed that you want to total the 12 months starting with the *present*
month.
I inserted a "+0" at the end of the first Index() segment, just in case you
want to start with the *next* month.
Then, just change the "+0" to
+1
And change the "+11" to
+12
 
P

paulkaye

That's perfect! But you know the problem now, right? I'm going to have
to go away and learn how it works! I've never used the MATCH function
but I can kind of see what you've done.

Thank you for your time,

Paul
 
R

RagDyer

You're welcome, and thank you for the feed-back.

In fact, because of your response, I see that I posted one of my test
formulas.by mistake.

You can try this revised, abbreviated version:

=SUM(INDEX(B2:B50,MATCH(TODAY(),A2:A50)+0):INDEX(B2:B50,MATCH(TODAY(),A2:A50)+11))

When I eliminated the "match type" argument of "0" (exact), that made
Today() an adequate lookup value on it's own, but I didn't post that version
after I finished testing.
Sorry!

As for what the formula does, you first of all see that it's a Sum()
formula.
Picture it totaling 12 rows, something like this:
=Sum(B16:B27)

Since the rows are in chronological order, and you needed 12 months totaled
up, it should be easy to comprehend that all we have to do to solve this, is
find the starting point of the sum range and then just simply extend it to
include 12 rows.

The Index() function is sort of complicated.
It can return a value that's in a cell, OR, the reference to the cell.
In this case we're using Index() in it's "reference" form, where it will
return a cell reference, *not* the contents of a cell.

As an example of these different forms, we index the Column B range that
contains the forecasts:

B2:B50

And let's start with B16, which is the *15th CELL* in that range:

=Index(B2:B50,15)

If B16 contains 100, the above formula will return that value ... 100.
If, say, H2 contained the number 15, then
=Index(B2:B50,H2)
Would do the same.

On the other hand, if we use it this way:
=Sum(Index(B2:B50,15):B27)

It will give us *exactly* the same results as:
=Sum(B16:B27)

Which will give us *exactly* the same results as:
=Sum(Index(B2:B50,15):Index(B2:B50,15+11))

So you see, all we really need to do is find out what actual number to place
in the position of the "15" that we used in the example.

This is accomplished using the Match() function.

Picture Match() as being a Vlookup or Hlookup function, *BUT* ... it returns
a reference to a cell, *NOT* the value in the cell!
And that reference is a *relative* reference, relating to the *position* of
the cell within the match range.

The syntax is:
Match(lookup value, lookup array, type of match)
Where "match type" is optional, and can be:
0 = Exact Match - lookup array can be in any order
omitted or 1 = Largest value that is less then or equal to lookup value -
lookup array must be sorted ascending
-1 = Smallest value that is greater then or equal to lookup value - lookup
array must be sorted descending

From here on, it's pretty much straight forward.

If you had, within the range - A2 to A50:
A22 = Sept-07
A23 = Oct-07
A24 = Nov-07

=Match(Today(),A2:A50)

Would return the number "22",
Which is A23 - Oct-07 - the *22nd CELL* in the lookup range.

So, if we now go back to our Sum formula, using the Index function:

=Sum(Index(B2:B50,15):Index(B2:B50,15+11))
Where we said that all we had to do was determine the proper value to use in
place of "15" to find the starting point,
We replace 15 with the Match formula:

=Sum(Index(B2:B50,Match(Today(),A2:A50)):Index(B2:B50,15+11))

And we also replace the second "15", and add the "+11":

=Sum(Index(B2:B50,Match(Today(),A2:A50)):Index(B2:B50,Match(Today(),A2:A50)+11))

And there you have your completed formula.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top