Summing Data based on a count of prior month data

pdbose

New Member
Joined
Jan 31, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hey Everyone!

Been following this site for a while now and finally posting something because I have spent the better part of all day today working on this and am complete stumped on how to solve for this one. Hoping someone can help! Screenshot below. I'm building out a forecasting model and I'm trying to come up with a formula that compares prior month sales to current sales by looking at the previous month's sales as a percentage of the total # of sales days for the current v previous month. In the data below. February has 23 business days and January has 19 business days. Since there are 2 business days of data for the current month, February (C2), the calculation should solve accordingly.

2 business days/23 business days (February) * 19 business days (January) = 1.65 days
So the formula should calculate $100 for the first business day in January, then 65% of the 2nd business day ($200) for a total of $230

Where things get tricky is this formula needs to adjust based on the selected month in C2 and find the correct columns in Row 11. It then needs to take the business days in Row 7 to run the calculation above, as well as go into an indirect function that allow me to lookup based off the "Remaining BD - xx" items in B12:B34. Essentially, this formula needs to sum everything within the range of "Remaining BD - 18" and Remaining BD - 17" for the January (since there's only 2 business days in February with populated values), while also applying the 65% calculation to the January value coinciding with "Remaining BD - 17". I'm able to create INDEX(MATCH()) functions and INDIRECT() functions that solve many of the problems individually but I'm unable to tie them all together without it breaking.

ForecastingTool.PNG
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I have some questions. You mention this is a "fore"casting model, yet your example calculates the first two days of a prior month, January, based on the first two days of sales in February? Don't you want the model to look ahead, rather than back in time?

this formula needs to sum everything within the range of "Remaining BD - 18" and Remaining BD - 17" for the January (since there's only 2 business days in February with populated values)
This wording suggests that the Sales numbers shown are daily sales numbers, not cumulative (i.e., not a running sum). Is this correct? Each cell with a sales number represents either actual or projected sales for that day only?

2 business days/23 business days (February) * 19 business days (January) = 1.65 days
So the formula should calculate $100 for the first business day in January, then 65% of the 2nd business day ($200) for a total of $230
Regarding this description, it appears that you want to generate a weighting factor based on the ratio of business days in one month relative to a baseline month (February in this case). But in your example, why is day 2 weighted at 65% when day 1 is not weighted at all? If I follow your description (and I have 23 business days of actual date for February...more on this below), then the first statement here would result in 23/23*19=19 days. I'm not sure what this is supposed to represent. What is the underlying assumption of this model? Is it that sales per month are expected to be the same, or sales per day? What is it about sales/day that would change depending on the number of days in the month?

Are the number of business days per month (e.g., 19 in January) based on a real schedule? If I use NETWORKDAYS.INTL for January and specify weekends as Saturday/Sunday non-work days, and then allow for two holidays, I get 21 work days. How was 19 determined?

I think the table structure does not lend itself well to the model described. Have you considered making the leftmost column be the Business Work Day number...so 1, 2, 3, etc. rather than counting down BD-22, BD-21, etc.? The advantage is that all months have BD 1, BD 2, etc. and since you want a forecast month's days to be based on the same days in a baseline month, all of the relevant "day" cells would then be on the same row, rather than potentially being offset from each other on different rows.

Could you clarify what you want to do, and offer a table that shows expected values?
 
Upvote 0
Thanks for the response! The model is a forecasting tool. However, this is for part of the tool that generates a snapshot of the actual sales performance for the current month. In this case, current actual sales vs prior month sales.

This wording suggests that the Sales numbers shown are daily sales numbers, not cumulative (i.e., not a running sum). Is this correct? Each cell with a sales number represents either actual or projected sales for that day only?
Yes, this is showing daily sales, not cumulative

Regarding this description, it appears that you want to generate a weighting factor based on the ratio of business days in one month relative to a baseline month (February in this case). But in your example, why is day 2 weighted at 65% when day 1 is not weighted at all? If I follow your description (and I have 23 business days of actual date for February...more on this below), then the first statement here would result in 23/23*19=19 days. I'm not sure what this is supposed to represent. What is the underlying assumption of this model? Is it that sales per month are expected to be the same, or sales per day? What is it about sales/day that would change depending on the number of days in the month?

Are the number of business days per month (e.g., 19 in January) based on a real schedule? If I use NETWORKDAYS.INTL for January and specify weekends as Saturday/Sunday non-work days, and then allow for two holidays, I get 21 work days. How was 19 determined?


For simplicity's sake, I'm going to say to ignore the business days piece of this and the weighted factor piece. It overcomplicates things. BTW, I calculated 19 business days by also removing the two company holidays that we recognize.

I realize my original post may have been unclear. The main challenge I'm facing is I need a formula that will count the numbers of days in February with reported sales, then sum the corresponding number of days of sales in January using that count. If February has 2 days of reported sales, the formula would look for the first populated value between rows 12 and 34 for January and then sum the correct numbers of days worth of sales based on that previous month count. Let me know if that clarifies things a bit and really appreciate your help!
 
Upvote 0
@KRice after doing some digging, I was able to put together this template formula which essentially calculates what I'm trying to solve.

=SUM(INDEX($C$12:$N$12,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)):INDEX(C12:C34,COUNTA(D12:D34)+(D7-C7),1))

However, the problem with this is that I have to find some way to get the part of the formula in red to adjust based on the value entered in C2. Because it is already using an index function, I can't use INDEX(MATCH()) functions to find C12:C34, D12:D34, D7 or C7.
 
Upvote 0
Thanks, that clarifies some questions, but I'm still not sure about several things. You are inputting data for February and then attempting to calculate values for the prior month, so why are you summing down the prior month (January) column in your last post? (see question below)

As for your last paragraph, if you only want the count of business days in February that have a non-0/non-blank value (let's say that number is n), and then you want the first n business days in January, you could find that readily using some Excel 365 functions. Are there two formula involved?...one to calculate daily sales for each business day in January, and another to sum only the first n business days in the prior month?
 
Upvote 0
See the yellow cell for a formula that counts the number of non-empty cells in the column to the right (again, let's call than number n), and then it looks down the range of values in rows 12:34 in that same column, filters out any blanks (which brings the 1st sale value to the top of the array), and then the TAKE function takes only the top n elements in the array and sums them.

In this case, the monthly forecast values are placed in each column using a formula that initially maps their locations...see that formula standing alone as an example in cell E12. That formula inserts blanks as necessary to offset the values, depending on how many business days are in that month. Jumping over to the C12 formula, you'll see that initial skeleton formula inside a MAP function. The MAP function walks along the skeleton array, element by element, and performs some type of calculation to generate a new value for that array location. That calculation is shown to the right in the formula, beginning with IF. This is the part that I do not understand. Right now the formula simply takes the ratios of the number of BDs for the two months and multiplies by the COUNTA results (so we get 1.65)...but I don't understand what you really want here.
MrExcel_20240131_C (version 1).xlsx
ABCDE
1
2Current MonthFebruary
3
4
5
6
7Business Days192321
8
93.3043478
10
11Business Work DayJanuaryFebruaryMarch
12Remaining BD - 22 100 
13Remaining BD - 21200
14Remaining BD - 201
15Remaining BD - 192
16Remaining BD - 181.65217393
17Remaining BD - 171.65217394
18Remaining BD - 161.65217395
19Remaining BD - 151.65217396
20Remaining BD - 141.65217397
21Remaining BD - 131.65217398
22Remaining BD - 121.65217399
23Remaining BD - 111.652173910
24Remaining BD - 101.652173911
25Remaining BD - 91.652173912
26Remaining BD - 81.652173913
27Remaining BD - 71.652173914
28Remaining BD - 61.652173915
29Remaining BD - 51.652173916
30Remaining BD - 41.652173917
31Remaining BD - 31.652173918
32Remaining BD - 21.652173919
33Remaining BD - 11.652173920
34Remaining BD - 01.652173921
Forecast
Cell Formulas
RangeFormula
C7C7=NETWORKDAYS.INTL(C11,EOMONTH(C11,0),1,$Q$2:$Q$15)
C9C9=SUM(TAKE(FILTER(C$12:C$34,C$12:C$34<>""),COUNTA(D$12:D$34)))
B12:B34B12="Remaining BD - "&SEQUENCE(23,,22,-1)
C12:C34C12=MAP(IF(C$7<23,VSTACK(EXPAND("",23-C$7,,""),SEQUENCE(C$7)),SEQUENCE(C$7)),LAMBDA(a,IF(a="","",C$7/D$7*COUNTA(D$12:D$34))))
E12:E34E12=IF(E$7<23,VSTACK(EXPAND("",23-E$7,,""),SEQUENCE(E$7)),SEQUENCE(E$7))
Dynamic array formulas.


Here is what prompted me to ask about the number of work days in the month. You can maintain a table of recognized holidays (national, local, company-only...doesn't matter) and that list will be ignored. And if the particular days of the week are not worked, that can be specified in the NETWORKDAYS.INTL formula. Here is a notional holiday reference table:
MrExcel_20240131_C (version 1).xlsx
QRS
1Days Off
21/1/2024Monday, January 01New Year’s Day
31/10/2024Company holiday
41/15/2024Monday, January 15MLK Day
51/19/2024Company holiday
62/19/2024Monday, February 19 *President’s Birthday
75/27/2024Monday, May 27Memorial Day
87/4/2024Thursday, July 04Independence Day
99/2/2024Monday, September 02Labor Day
1010/14/2024Monday, October 14Indigenous Peoples' Day
1111/5/2024Election Day
1211/28/2024Thursday, November 28Thanksgiving Day
1312/25/2024Wednesday, December 25Christmas Day
141/1/2025Wednesday, January 01New Year’s Day
151/20/2025MLK Day
Forecast
 
Upvote 0
2 business days/23 business days (February) * 19 business days (January) = 1.65 days
So the formula should calculate $100 for the first business day in January, then 65% of the 2nd business day ($200) for a total of $230
In post #2, I asked for more detail about expected results. Would you please show a few columns and 5 or 6 rows of results showing what the expected results are, and which values are already present in the table, and where formulas are needed? The image in the original post does not explain these things. The explanation quoted above from the original post is unclear. My initial interpretation was that you wanted a formula to populate values in a prior month while you manually enter data in the current month (whichever month is shown in C2)...but when you advance to the following month (say March), the February column would not have a formula (as it contains the manually entered data). So I suspect this understanding is not correct. My second guess is that rows 12:34 contain data that is manually entered, with no formulas involved...and you want a formula that delivers a single result showing some type of sum based on the prior month's daily sales data, the current month's developing sales data, and the number of days populated with data in the current month.

Generally, it is advisable to use the XL2BB add-in so that you can post a small working example of your worksheet, which helps others understand the problem, where data are found and structured, and where formulas are needed...and this greatly facilitates developing solutions.
 
Upvote 0
Thanks for taking so much time to help out with this! I'll see if I can add the XL2BB add-in. I may have to get permission from my org as they are extremely strict on what we can and can't download on these computers. In the meantime, to help make this a little more clear, here is the "summary" that I present to my teams. Obviously, the values are not real so ignore that none of the percentages make sense.

InkedExampleforExcelForum.jpg


What we're solving for is circled in red. This is showing how current sales aligns to the Last Month sales to date. Currently, it is using an insanely long formula that I don't want to post because I think it would cause more confusion. However, the issue with this current formula is that, until sales for February hit row 16 (because that's when January started on the sheet), it shows N/A. Once it hits row 16, it shows results like this (900%) because it's comparing the 1st 5 days of February sales to the first day of January sales. For months that have the same business days, this obviously isn't an issue. However, when there's a significant variation, in the case of January and February of this year, it skews values for weeks. This is what I'm ultimately trying to correct.
 
Upvote 0
So far, I have this as my formula and it is giving me the correct sum. However, I still can't figure out how to get the part highlighted in red to dynamically adjust to the value in C2.

=SUM(INDEX($C$12:$N$12,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)):INDEX($C$12:$N$34,COUNTA(D12:D34)+(D7-C7),MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)))
 
Upvote 0
I think I may have figure it out!

=SUM(INDEX($C$12:$N$12,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)):INDEX($C$12:$N$34,COUNTA(INDEX($C$12:$N$34,0,MATCH($C$2,$C$11:$N$11,0)))+(INDEX($C$7:$N$7,1,MATCH($C$2,$C$11:$N$11,0))-INDEX($C$7:$N$7,1,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0))),MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)))


Then, in order to get the comparison to last month, I would use

=(INDEX($C$35:$N$35,1,MATCH($C$2,$C$11:$N$11,0))-SUM(INDEX($C$12:$N$12,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)):INDEX($C$12:$N$34,COUNTA(INDEX($C$12:$N$34,0,MATCH($C$2,$C$11:$N$11,0)))+(INDEX($C$7:$N$7,1,MATCH($C$2,$C$11:$N$11,0))-INDEX($C$7:$N$7,1,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0))),MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0))))/SUM(INDEX($C$12:$N$12,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)):INDEX($C$12:$N$34,COUNTA(INDEX($C$12:$N$34,0,MATCH($C$2,$C$11:$N$11,0)))+(INDEX($C$7:$N$7,1,MATCH($C$2,$C$11:$N$11,0))-INDEX($C$7:$N$7,1,MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0))),MATCH(DATE(YEAR($C$2),MONTH($C$2)-1,1),$C$11:$N$11,0)))
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,165
Members
452,615
Latest member
bogeys2birdies

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