• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

SUM variable number of rows

mr_hiboy

Member
hello all,

I was wondering if it was possible to lookup a date value in one column, then sum the values in the next column for variable number of rows, eg.

Data
DATE PRICE
01/4/15 10
02/04/15 11
03/04/15 11
04/04/15 10
...

Then i have cells with date and number of nights e.g.
Date Nights Price
01/04/15 3 ???

Am I able to have a formula that looks up 1/4/15, then sums three rows to give me to the total 32?

Hope that makes sense?
thanks
Paul
 
Dear mr-hiboy

For this specific scenario a formula such as

=SUMIFS(D7:D13,C7:C13,">="&C18,C7:C13,"<"&C18+D18)

works.

For a more general formula (one that doesn't rely on the values in column C increasing by 1 each row) then

=SUM((IF(((1+ROW(C7:C13)-ROW(C7))<=(MATCH(C18,C7:C13,0)+D18)-1)+(ROW(C7:C13)-ROW(C7)>=(MATCH(C18,C7:C13,0)-1))=2,1,0))*(D7:D13))

seems to work
 
Last edited:
Works a treat, thank you very much.

Like the logic, I'll be able use that going forward :)


Dear mr-hiboy

For this specific scenario a formula such as

=SUMIFS(D7:D13,C7:C13,">="&C18,C7:C13,"<"&C18+D18)

works.

For a more general formula (one that doesn't rely on the values in column C increasing by 1 each row) then

=SUM((IF(((1+ROW(C7:C13)-ROW(C7))<=(MATCH(C18,C7:C13,0)+D18)-1)+(ROW(C7:C13)-ROW(C7)>=(MATCH(C18,C7:C13,0)-1))=2,1,0))*(D7:D13))

seems to work
 
Back
Top