Help with formula to sum numbers prior to date

ExcelAtEverything

Active Member
Joined
Jan 30, 2021
Messages
308
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I was hoping to get some assistance as I'm having trouble with this. Using my table below as an example, how could I write a formula which will basically say:

* For each store, add all monthly dollar amounts for months that occur prior to the month of the "Reporting Date" in $B$2. (or in this case, Jan & Feb)

*For the month in the table which is equal to the "Reporting Date" in $B$2 (in this case, March), I would like to take the daily average of the dollar amount shown for that month (divided evenly by # days in that month (in this case 31)), and multiply by the number of days that have passed so far in the "Reporting Date" $B$2 (specifically up to but not including the "Reporting Date"). In other words using the displayed table, for the month of March (since that's a partial month due to the "Reporting Date"), Instead of entering $100, I would only enter $87.21 (since that is an estimated amount based on the "Reporting Date".

Thank you.

1617963238870.png
 

ExcelAtEverything

Active Member
Joined
Jan 30, 2021
Messages
308
Office Version
  1. 2019
Platform
  1. Windows
Oh I see. You are close. Since the report date is the 3/28, it needs to include only up to the 27th, and not include the 28th. You are including the 28th in your calculation. The report date assumes it is the morning and you are running all the sales reports for the prior day. So if the report date is the 28, you would not yet have the numbers for the 28, because it would be the morning of the 28th. Make sense?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Andy Pilkington

Board Regular
Joined
Jan 23, 2014
Messages
65
Office Version
  1. 2019
Platform
  1. Windows
The single day adjustment is an easy fix but if the other results are what you are looking for I can share the spreadsheet with you. What I have sent to you shows only the information which I have assumed you really want to see. The formulas I have kept on a separate worksheet so that it can be protected and not be allowed to confuse your working data.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,135
Office Version
  1. 365
Platform
  1. Windows
Does this do what you want
+Fluff 1.xlsm
ABCDEFGHIJKLMNOP
1
225/03/2021
3
4To DateJanFebMarAprMayJunJulAugSepOctNovDecTotal
5327.419355Loc11001501001501501601701801902002102201980
6604.83871Loc22002502002502602702802903003103203303260
Results
Cell Formulas
RangeFormula
B5:B6B5=SUMPRODUCT((MONTH($D$4:$O$4&1)<MONTH($B$2))*(D5:O5))+INDEX(D5:O5,MONTH($B$2))*(DAY($B$2)-1)/DAY(EOMONTH($B$2,0))
P5:P6P5=SUM(D5:O5)
 

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,224
Office Version
  1. 2013
Platform
  1. Windows
Does this help?
You need to ensure the year applicable to data is in C1. That will generate correct end dates in C2:O2

Book1
BCDEFGHIJKLMNOPQR
1ReportData YearEOMEOMEOMEOMEOMEOMEOMEOMEOMEOMEOMEOM
228/03/2021202131/01/202128/02/202131/03/202130/04/202131/05/202130/06/202131/07/202131/08/202130/09/202131/10/202130/11/202131/12/2021
3
4JanFebMarAprMayJunJulAugSepOctNovDecTotalTo Date
5Loc11001501001501501601701801902002102201980337.0968
6Loc22002502002502602702802903003103203303260624.1935
Sheet1
Cell Formulas
RangeFormula
D2:O2D2=EOMONTH("01/01/" &$C2,COLUMNS($D:D)-1)
P5:P6P5=SUM(D5:O5)
R5:R6R5=MIN(P5,SUMIF($D$2:$O$2,"<"&$B$2,D5:O5)+INDEX(D5:O5,MONTH($B$2))*(DAY($B$2)-1)/DAY(EOMONTH($B$2,0)))



 
Solution

ExcelAtEverything

Active Member
Joined
Jan 30, 2021
Messages
308
Office Version
  1. 2019
Platform
  1. Windows
Something seems to be off. It is returning a #value error. A few things:

1) Row #2 pasted in with hyperlinks and formatted to General, so I removed hyperlinks and reformatted to a short date format.
2) "2021" formatted as General (when I try to change it to custom or date, it changes to that 01/01/1900 logic.
3) I broke apart the formula so I could follow what you are doing, but I'm having difficulty because each part that I test on it's own seems like it comes back as an error or "0" except for this part (...SUMIF($D$2:$O$2,"<"&$B$2,D5:O5)... which returns "$150". And even that seems incorrect, as this appears to be the part that is tallying the completed months that have passed... yet it skips January and only includes February. Most or all other arguments either return "0" or an error message.

Am I doing something incorrectly?
 

Watch MrExcel Video

Forum statistics

Threads
1,132,640
Messages
5,654,539
Members
418,139
Latest member
nimesh72

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
Top