Sum adjacent cells based on criteria

spoony40

New Member
Joined
Feb 27, 2015
Messages
17
Hi, I need some help with a sum formula that adds a range based on a criteria.

The criteria is the cell value "Mar-18" which changes.

When its "Mar-18", it will sum the values for "Apple" for the month of "Jan-18", "Feb-18" and "Mar-18" which results in "9".

The "Next Qtr" value is the sum of the next 3 months ie. "Apr-18", "May-18" and "June-18" which results in "18".

Anyone knows how to do write these 2 formulas?

Thanks


TypeMar-18 Next Qtr
Jan-18

<tbody>
</tbody>
Feb-18

<tbody>
</tbody>
Mar-18

<tbody>
</tbody>
Apr-18

<tbody>
</tbody>
May-18

<tbody>
</tbody>
Jun-18

<tbody>
</tbody>
Jul-18

<tbody>
</tbody>
Aug-18

<tbody>
</tbody>
Apple91823456789
Orange62713279111315

<tbody>
</tbody>


TypeApr-18 Next Qtr
Jan-18

<tbody>
</tbody>
Feb-18

<tbody>
</tbody>
Mar-18

<tbody>
</tbody>
Apr-18

<tbody>
</tbody>
May-18

<tbody>
</tbody>
Jun-18

<tbody>
</tbody>
Jul-18

<tbody>
</tbody>
Aug-18

<tbody>
</tbody>
Apple122123456789
Orange123813279111315


<tbody>
</tbody>
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
To make it abit clearer, i need the formula to calculate the sum of months jan/feb/mar, the "9" total, given the criteria "Mar-18". Also the formula to calculate the sum of apr/may/jun-18 given mar-18.
 
Upvote 0
Hi,

If I understand correctly, this will do what you want, although I think your Orange sum for Apr-18 is incorrect in your sample (instead of 38, should be 33):


Book1
ABCDEFGHIJK
1TypeApr-18Next QtrJan-18Feb-18Mar-18Apr-18May-18Jun-18Jul-18Aug-18
2Apple122123456789
3Orange123313279111315
Sheet7
Cell Formulas
RangeFormula
B2=SUMPRODUCT((MONTH(D$1:K$1)<=MONTH(B$1))*(MONTH(D$1:K$1)>MONTH(B$1)-3)*D2:K2)
C2=SUMPRODUCT((MONTH(D$1:K$1)>MONTH(B$1))*(MONTH(D$1:K$1)<=MONTH(B$1)+3)*D2:K2)


Formulas copied down.
 
Upvote 0
Actually, when the months cross over to the next year, it doesn't work. eg

Dec-18, jan-19, feb-19
 
Upvote 0
Thanks, it works

Actually, when the months cross over to the next year, it doesn't work. eg

Dec-18, jan-19, feb-19

You're welcome, I actually overcomplicated the formula that didn't account for crossing over the next year, use this updated formula, should work fine:


Book1
ABCDEFGHIJKLMNOPQ
1TypeNov-18Next QtrJan-18Feb-18Mar-18Apr-18May-18Jun-18Jul-18Aug-18Sep-18Oct-18Nov-18Dec-18Jan-19Feb-19
2Apple122123456789345678
3Orange152413279111315456789
Sheet7
Cell Formulas
RangeFormula
B2=SUMPRODUCT((D$1:Q$1<=B$1)*(D$1:Q$1>EOMONTH(B$1,-3))*D2:Q2)
C2=SUMPRODUCT((D$1:Q$1>B$1)*(D$1:Q$1<=EOMONTH(B$1,3))*D2:Q2)
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,447
Members
449,453
Latest member
jayeshw

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