SUMIFS? Other formula? Confusion working with date ranges and individual numerical days

anpathea

New Member
Joined
Feb 9, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hello!

I've been trying to work through this issue via Google but just can't figure it out.

In Column B there are numbers relating to the monthly bill due dates, but does not express full dates. In other words, it is only the DD from a MM/DD/YYYY date.

In Column C are the costs associated with those bills in dollar amounts.

In Column I there is a sequential list of full dates (e.g. 2/4/2022, 2/9/2022, 3/7/2022, etc.).

In Column J, I am attempting to create a formula that adds up all values in C that fall between two dates from I, using the numerical days from B.

For example, in J22, I want to pull costs from Column C for due dates > 2/4/2022 (I21) and <=2/18/2022 (I22), using the Column B due dates. The problem I'm running into is I cannot figure out how to get Excel to work between a single number that represents the DD part of the date and the actual dates.

I keep running into the same problems where I am able to make it work for dates where the DD range goes up (e.g. the dates in the previous line, > 4, <= 18), but it doesn't work when it goes from one month to the next because something like March 25 to April 9 tries to pull anything > 25 and <= 9, which obviously results in nothing. Every time I think I've found a workaround, it ends up being exactly the same thing, and I just don't think my Excel skills or my Google skills are up to the task without some help. What I need is a single formula that I can drag down Column J that will reliably work.

Let me know if I can clarify anything! It's super confusing to me, so it's difficult to explain.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Welcome to the Forum!

The first thing to establish is what's actually in your DD cells.

Excel stores dates as numbers. Today (10 Feb 2022) is stored as 44,602. Tomorrow will be 44,603.

Range A2:A5 below all contains the same number 44,602. But is is displayed differently depending on the format chosen.

AB
1TodayFormat
2Thu 10 Feb 2022ddd d mmm yyyy
310dd
402-10-22mm-dd-yy
544,602#,##0
qw
Cell Formulas
RangeFormula
A2:A5A2=TEXT(TODAY(),B2)

So if you have a DD cell that displays as 10, say, is the number in the cell actually 10? Or has it perhaps just been formatted to display as 10?
 
Upvote 0
Welcome to the Forum!

The first thing to establish is what's actually in your DD cells.

Excel stores dates as numbers. Today (10 Feb 2022) is stored as 44,602. Tomorrow will be 44,603.

Range A2:A5 below all contains the same number 44,602. But is is displayed differently depending on the format chosen.

AB
1TodayFormat
2Thu 10 Feb 2022ddd d mmm yyyy
310dd
402-10-22mm-dd-yy
544,602#,##0
qw
Cell Formulas
RangeFormula
A2:A5A2=TEXT(TODAY(),B2)

So if you have a DD cell that displays as 10, say, is the number in the cell actually 10? Or has it perhaps just been formatted to display as 10?
Thanks for the quick response!

I did not even consider changing those cells to a different format, so they are just 'General.'

I'm guessing I can do something if I change them to a date format?
 
Upvote 0
... I am able to make it work for dates where the DD range goes up (e.g. the dates in the previous line, > 4, <= 18) ...
Sorry, I've probably led you astray with Post #2. It sounds like your due dates are days of the month, e.g. 10, 15.

Here's one way you can count the number of due days on and between two dates:

ABCDE
1Date1Date2DueDayNoTimes
220 Jan 20223 Feb 202211
320 Jan 20223 Feb 2022311
420 Jan 20223 Feb 202260
531 Jan 202228 Feb 2022301
620 Jan 202223 Mar 202272
720 Jan 20226 Mar 202262
86 Jan 20226 Mar 202263
920 Dec 20224 Jan 2023201
Sheet1
Cell Formulas
RangeFormula
E2:E9E2=IF(OR(A2>B2,C2<1,C2>31),"-",12*(YEAR(B2)-YEAR(A2))+MONTH(B2)-MONTH(A2)+(C2>=DAY(A2))-(MIN(DAY(EOMONTH(B2,0)),C2)>DAY(B2)))

Is this something you can adapt?
 
Upvote 0
Sorry, I've probably led you astray with Post #2. It sounds like your due dates are days of the month, e.g. 10, 15.

Here's one way you can count the number of due days on and between two dates:

ABCDE
1Date1Date2DueDayNoTimes
220 Jan 20223 Feb 202211
320 Jan 20223 Feb 2022311
420 Jan 20223 Feb 202260
531 Jan 202228 Feb 2022301
620 Jan 202223 Mar 202272
720 Jan 20226 Mar 202262
86 Jan 20226 Mar 202263
920 Dec 20224 Jan 2023201
Sheet1
Cell Formulas
RangeFormula
E2:E9E2=IF(OR(A2>B2,C2<1,C2>31),"-",12*(YEAR(B2)-YEAR(A2))+MONTH(B2)-MONTH(A2)+(C2>=DAY(A2))-(MIN(DAY(EOMONTH(B2,0)),C2)>DAY(B2)))

Is this something you can adapt?
This is very cool!

To be clear, this is counting the number of times the due date exists between the two dates, right? That seems to be the case, but row 5 is not working properly. Between 31 Jan and 28 Feb, there should be zero instances of the date “30,” but it is showing 1.

I definitely like this idea though, I may play around with it later to see if I can figure it out, but if you know what’s happening that might be quicker!

Really appreciate the expertise!
 
Upvote 0
To be clear, this is counting the number of times the due date exists between the two dates, right? That seems to be the case, but row 5 is not working properly. Between 31 Jan and 28 Feb, there should be zero instances of the date “30,” but it is showing 1.
Yes, that's the intention.

If a bill falls due on the 31st of the month, my calculation assumes it will be paid on 31 Jan, 28/9 Feb, 31 March, 30 April .....

Please post back if you need further assistance. It's best if you can provide a screenshot using our XL2BB add-in, which you can download here: XL2BB - Excel Range to BBCode
 
Upvote 0
Yes, that's the intention.

If a bill falls due on the 31st of the month, my calculation assumes it will be paid on 31 Jan, 28/9 Feb, 31 March, 30 April .....

Please post back if you need further assistance. It's best if you can provide a screenshot using our XL2BB add-in, which you can download here: XL2BB - Excel Range to BBCode
Oh, of course! That makes perfect sense.

I’ll try implementing this later and see how it goes! Thanks again!
 
Upvote 0
One more option 28 Feb not be counted with 29/30/31:
Code:
=SUMPRODUCT(--(DAY(ROW(INDIRECT(A2&":"&B2)))=C2))
Capture.JPG
 
Upvote 0
I figured it out!

This is long because I’m recapping everything because I went a different route, and because I don’t think the question I posed initially is as clear as I can present it here.

I genuinely appreciate the help you all provided, even though I did not ultimately use it in the solution. The guidance helped me think through the problem. I struggled to articulate my problem and needs initially, which made it more confusing than it had to be and led the responses astray a bit. That’s totally my fault, but also my inability to articulate everything was part of the reason I was running into the issues in the first place, so that makes sense.

If you’re curious about the solution, read on!

See the mini sheet below for an example of what my spreadsheet looks like starting out. “Manual Check” is literally just what the numbers should match (I noticed later there was an error in one of those, which is the whole reason I wanted this automated, aside from saving time).

Budget.xlsx
ABCDEFGH
1Pay ToDue DatePaymentDate 1Date 2Payment DueManual Check
2Category 11/5/20221/19/2022$2,871.62
3Lorem2$45.131/19/20222/2/2022$1,484.91
4Ipsum9$120.502/2/20222/16/2022$2,871.62
5Category 22/16/20223/2/2022$1,484.91
6Dolor7$281.253/2/20223/16/2022$2,871.62
7Sit13$1,350.003/16/20223/30/2022$589.68
8Amet22$152.533/30/20224/13/2022$2,657.09
9Category 34/13/20224/27/2022$1,262.29
10Consectet1$75.254/27/20225/11/2022$1,182.09
11Abipsic9$10.115/11/20225/25/2022$2,612.29
12Elit15$134.435/25/20226/8/2022$1,613.63
13Donec31$125.006/8/20226/22/2022$2,742.90
14Category 46/22/20227/6/2022$1,332.38
15Guble2$649.857/6/20227/20/2022$2,871.62
16Rebo15$975.337/20/20228/3/2022$1,484.91
17Innil29$437.158/3/20228/17/2022$2,871.62
Sheet1
Cell Formulas
RangeFormula
H2H2=C4+C6+C7+C11+C12+C16
H3H3=C3+C8+C10+C13+C15+C17
H4H4=C4+C6+C7+C11+C12+C16
H5H5=C3+C8+C10+C13+C15+C17
H6H6=C4+C6+C7+C11+C12+C16
H7H7=C8+C17
H8H8=C3+C4+C6+C7+C10+C11+C13+C15
H9H9=C8+C12+C16
H10H10=C3+C4+C6+C10+C11+C15
H11H11=C7+C8+C12+C16
H12H12=C3+C6+C10+C13+C15+C17
H13H13=C4+C7+C8+C11+C12+C16
H14H14=C3+C10+C13+C15+C17
H15H15=C4+C6+C7+C11+C12+C16
H16H16=C3++C8+C10+C13+C15+C17
H17H17=C4+C6+C7+C11+C12+C16


What I need is for each cell in G to sum the values of Payment (C:C) where Due Date (B:B) falls in the range > DAY(E) and <=(F).



My initial attempt, even before posing the question here, was using the following formula:



=SUMIFS(C:C,B:B,">"&DAY(E2),B:B,"<="&DAY(F2))



But this doesn’t work when DAY(E2) > DAY(F2):



Budget.xlsx
EFGH
1Date 1Date 2Payment DueManual Check
21/5/20221/19/20222871.62$2,871.62
31/19/20222/2/20220$1,484.91
42/2/20222/16/20222871.62$2,871.62
52/16/20223/2/20220$1,484.91
63/2/20223/16/20222871.62$2,871.62
73/16/20223/30/2022589.68$589.68
Sheet1
Cell Formulas
RangeFormula
G2:G7G2=SUMIFS(C:C,B:B,">"&DAY(E2),B:B,"<="&DAY(F2))
H2H2=C4+C6+C7+C11+C12+C16
H3H3=C3+C8+C10+C13+C15+C17
H4H4=C4+C6+C7+C11+C12+C16
H5H5=C3+C8+C10+C13+C15+C17
H6H6=C4+C6+C7+C11+C12+C16
H7H7=C8+C17




I understood what the problem was, but couldn’t figure out the solution, and this is when I posed my initial question. While working on it today, I decided to try to come up with a formula that works for the other situations, knowing it would not work for the prior situation, and came up with this:



=(SUMIFS(C:C,B:B,">"&DAY(E3),B:B,"<32"))+(SUMIFS(C:C,B:B,"<="&DAY(F3),B:B,">0"))

I don’t know if these are the best formula for either situation, but I know they work:

Budget.xlsx
EFGH
1Date 1Date 2Payment DueManual Check
21/5/20221/19/20222871.62$2,871.62
31/19/20222/2/20221484.91$1,484.91
42/2/20222/16/20222871.62$2,871.62
52/16/20223/2/20221484.91$1,484.91
63/2/20223/16/20222871.62$2,871.62
73/16/20223/30/2022589.68$589.68
83/30/20224/13/20222657.09$2,657.09
Sheet1
Cell Formulas
RangeFormula
G2,G4,G6:G7G2=SUMIFS(C:C,B:B,">"&DAY(E2),B:B,"<="&DAY(F2))
H2H2=C4+C6+C7+C11+C12+C16
G3,G5,G8G3=(SUMIFS(C:C,B:B,">"&DAY(E3),B:B,"<32"))+(SUMIFS(C:C,B:B,"<="&DAY(F3),B:B,">0"))
H3H3=C3+C8+C10+C13+C15+C17
H4H4=C4+C6+C7+C11+C12+C16
H5H5=C3+C8+C10+C13+C15+C17
H6H6=C4+C6+C7+C11+C12+C16
H7H7=C8+C17
H8H8=C3+C4+C6+C7+C10+C11+C13+C15


I figured an IF formula would work here. I ended up hitting a bunch of snags along the way with various syntax issues and because I was being careless when combining them (I copied and pasted the working formulas to make sure they worked, but since I made the second formula using different reference cells, the combined formula tried to use four different cells instead of two). Anyway, I the following is the working formula:

=IF(DAY(E2)<DAY(F2),(SUMIFS(C:C,B:B,">"&DAY(E2),B:B,"<="&DAY(F2))),(SUMIFS(C:C,B:B,">"&DAY(E2),B:B,"<32"))+(SUMIFS(C:C,B:B,"<="&DAY(F2),B:B,">0")))

You can see the functioning, solved spreadsheet here:

Budget.xlsx
ABCDEFGH
1Pay ToDue DatePaymentDate 1Date 2Payment DueManual Check
2Category 11/5/20221/19/20222871.62$2,871.62
3Lorem2$45.131/19/20222/2/20221484.91$1,484.91
4Ipsum9$120.502/2/20222/16/20222871.62$2,871.62
5Category 22/16/20223/2/20221484.91$1,484.91
6Dolor7$281.253/2/20223/16/20222871.62$2,871.62
7Sit13$1,350.003/16/20223/30/2022589.68$589.68
8Amet22$152.533/30/20224/13/20222657.09$2,657.09
9Category 34/13/20224/27/20221262.29$1,262.29
10Consectet1$75.254/27/20225/11/20221744.24$1,744.24
11Abipsic9$10.115/11/20225/25/20222612.29$2,612.29
12Elit15$134.435/25/20226/8/20221613.63$1,613.63
13Donec31$125.006/8/20226/22/20222742.9$2,742.90
14Category 46/22/20227/6/20221332.38$1,332.38
15Guble2$649.857/6/20227/20/20222871.62$2,871.62
16Rebo15$975.337/20/20228/3/20221484.91$1,484.91
17Innil29$437.158/3/20228/17/20222871.62$2,871.62
Sheet1
Cell Formulas
RangeFormula
G2:G17G2=IF(DAY(E2)<DAY(F2),(SUMIFS(C:C,B:B,">"&DAY(E2),B:B,"<="&DAY(F2))),(SUMIFS(C:C,B:B,">"&DAY(E2),B:B,"<32"))+(SUMIFS(C:C,B:B,"<="&DAY(F2),B:B,">0")))
H2H2=C4+C6+C7+C11+C12+C16
H3H3=C3+C8+C10+C13+C15+C17
H4H4=C4+C6+C7+C11+C12+C16
H5H5=C3+C8+C10+C13+C15+C17
H6H6=C4+C6+C7+C11+C12+C16
H7H7=C8+C17
H8H8=C3+C4+C6+C7+C10+C11+C13+C15
H9H9=C8+C12+C16
H10H10=C3+C4+C6+C10+C11+C15+C13+C17
H11H11=C7+C8+C12+C16
H12H12=C3+C6+C10+C13+C15+C17
H13H13=C4+C7+C8+C11+C12+C16
H14H14=C3+C10+C13+C15+C17
H15H15=C4+C6+C7+C11+C12+C16
H16H16=C3++C8+C10+C13+C15+C17
H17H17=C4+C6+C7+C11+C12+C16
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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