Sum Formula Needed Across Months by # of Days

BrettOlbrys1

Board Regular
Joined
May 1, 2018
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hello. In column A I have data I want to sum and in column B I have the corresponding date. For example:

79/1/21
39/2/21
209/23/21
510/3/21
610/5/21

Since today is 10/14/21, I want to sum and compare only the cells in column A that are within the first 14 days of the month. So I would see that for September, the sum would be 10 and for October it would be 11. This needs to be dynamic because whenever I run the report, today's date will be the day that I compare the current month to vs the prior month (based on the number of days in the month today is).
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I would add 2 columns after your data. 1) DateDiff (that will calc the difference in days & 2) Filter (an IF formula where it will put the word "Add" or a blank cell depending on if it is within the 14 days) 3) a spot to put in today's date (i used the =Today() formula in that cell. The DateDiff formula will be: =DATEDIF(B2,$E$1,"D") . The Filter formula is =IF(C2<=14,"Add","") determines if its <= 14 days, if it is, then the word "Add" will be put in, otherwise it will be a blank.
A B C D E
View attachment 49085
my data starts in Column A; I would also make the DataRange a filtered range so I could filter on Column D- if it equals 'Add', then sum up amounts.
 

Attachments

  • 1634236826700.png
    1634236826700.png
    7.7 KB · Views: 5
Upvote 0
the SUMIF() would be used
=SUMIF(B1:B5,">="&TODAY()-14,A1:A5)

BUT not sure I understand, I'm using the function today() and then subtracting 14 days - so it will be dynamic and based on the date the spreadsheet is open
This needs to be dynamic because whenever I run the report, today's date will be the day that I compare the current month to vs the prior month (based on the number of days in the month today is).

Round.xlsm
ABCD
179/1/21
239/2/2111
3209/23/21
4510/3/21
5610/5/21
Sheet1
Cell Formulas
RangeFormula
D2D2=SUMIF(B1:B5,">="&TODAY()-14,A1:A5)
 
Upvote 0
If im reading correctly:

=SUMIFS(A:A,B:B,">="&EOMONTH(TODAY(),-1)+1)

and

=SUMIFS(A:A,B:B,">="&EOMONTH(TODAY(),-2)+1,B:B,"<"&EDATE(TODAY(),-1)+1)
 
Upvote 0
I came up with this formula to get me the same number of days at the same time last month:

=(EOMONTH(TODAY(),-2)+1)+((TODAY()-EOMONTH(TODAY(),-1)+1)-2)

But this will fail when/if I run the report during March on the 29th, 30, or 31st because February doesn't have those days OR if I run it on the 31st of a month and the preceding month only has 30 days.
 
Upvote 0
I am thinking that you may need to have two hidden columns "C" Month Code which uses the formula MONTH(B2) where B2 = the date. Then Column D which uses a formula =DAY(B2)<=DAY(NOW()) to get the day of the month from both the month in column B and today's day of the month and determines if it is earlier or later than today's day of month.

For Last Month I used the formula =SUMIFS($A$2:$A$2000,$C$2:$C$2000,MONTH(NOW())-1,$D$2:$D$2000,TRUE)
For this Month I used the formula =SUMIFS($A$2:$A$2000,$C$2:$C$2000,MONTH(NOW()),$D$2:$D$2000,TRUE)

Basically it is saying - Sum A2 to A2000 where Column C=Month and D=True.

OptOut_Stats_Chart.xlsx
ABCDEFGH
1ItemsDateMONTH CODEDAY OF MONTH <= TODAY
279/1/219TRUE
339/2/219TRUE
4209/23/219FALSE
5510/3/2110TRUELast Month10
6610/5/2110TRUEThis Month11
71TRUE
81TRUE
Sheet2
Cell Formulas
RangeFormula
C2:C8C2=MONTH(B2)
D2:D8D2=DAY(B2)<=DAY(NOW())
H5H5=SUMIFS($A$2:$A$2000,$C$2:$C$2000,MONTH(NOW())-1,$D$2:$D$2000,TRUE)
H6H6=SUMIFS($A$2:$A$2000,$C$2:$C$2000,MONTH(NOW()),$D$2:$D$2000,TRUE)
 
Upvote 0
Ive given you one. Take it from the reply you havent tried it? EDATE will happily deal with the 29th March producing 28th February (unless a leap year).
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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