Sumifs between date / Check whether date is first half of month or second half

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hello Dear community,

I want to use SUMIFS but probably 1 formula can't handle it.
I have list of sales by dates. For example:
Purchase date is 10/21/2023
I need to sum between 10/16/2023 to End of that month
If Purchase date is 10/11/2023
Then I need to sum between 10/01/2023 to 10/15/2023

I need to get result whether date is first half of month or second and sum by that dates.

Hope someone can help me.
Thanks in advance!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
When asking this type of question it helps to explain where your dates are (what column? what rows?) and where is the data you want to sum.

If dates are in column A and amounts are in column B

First half
Excel Formula:
=SUMIFS(B:B,A:A,">="&Date(2023,10,1),A:A,"<="&Date(2023,10,15))
second half
Excel Formula:
=SUMIFS(B:B,A:A,">="&Date(2023,15,1),A:A,"<="&Date(2023,10,31))
 
Upvote 0
Please try this:

Book3
GHIJK
1Sum
2Purchase Date:10/16/202318
310/1/20231
410/2/20232
510/3/20233
610/11/20234
710/16/20235
810/23/20236
910/31/20237
Sheet1
Cell Formulas
RangeFormula
K2K2=SUMIFS(H3:H9,G3:G9,">="&(IF(DAY(J2)>15,DATE(YEAR(J2),MONTH(J2),15),DATE(YEAR(J2),MONTH(J2),1))),G3:G9,"<="&(IF(DAY(J2)>15,EOMONTH(J2,0),DATE(YEAR(J2),MONTH(J2),15))))
 
Upvote 2
Thank you for the reply, I know to use SUMIFS, just my goal it to detect whether date is first or second half of the month and make calculations for that.
I figured out. But only problem date is showing 1 day before the day I use.
For example: secondDate = should be day 15 but it shows 14. I had same problem before, I was thinking CDate will solve it, but still have same problem. Would be glad if someonce have idea why it is like this.
VBA Code:
                            firstDate = CDate(DateSerial(Year(ws.Range("H" & x)), Month(ws.Range("H" & x)), Day(1)))
                            secondDate = CDate(DateSerial(Year(ws.Range("H" & x)), Month(ws.Range("H" & x)), Day(15)))
                            
                            'Get Price-W
                            Dim PriceW As Double
                            PriceW = WorksheetFunction.SumIfs(wks.Range("H:H"), wks.Range("C:C"), ws.Cells(x, 9 + i).Value, _
                            wks.Range("F:F"), ">=" & firstDate, _
                            wks.Range("F:F"), "<=" & secondDate)
 
Upvote 0
Don't use Day(1) and Day(15) just use 1 and 15

It would have been nice if your initial post had said you were using VBA.
 
Upvote 1
Solution
Thank you so much for both solutions. Jeffreys solutions is great to use as function!
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,337
Members
453,032
Latest member
Pauh

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