Formula to calculate dynamic average of monthly costs

vladimiratanasiu

Active Member
Joined
Dec 17, 2010
Messages
348
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello!

I posted a topic about one week ago (Calculate dynamic average of monthly costs), but didn't get yet a proper solution. Basically, I have a multiannual situation (see C2:C40) with monthly expenses, that are updated continuously with new information (e.g. C35:C39 and so on). Some cells show total expenses of a year (e.g C14, C27, C40 etc.). I need a dynamic formula to calculate the average value of all months, including automatically the new added ones but ignoring the annual totals. I've got the formula from the attached table, but it must be operated manually each time new data are inserted ( e.g. C34 / April 2023) and doesn't take automatically into account other new values added after that period (e.g. C35:C39). In these conditions, I need one solution (formula, macro) to generate a single result that moves down progressively in line with the last value available (see column D), or working in a merged range that expensed automatically when are added new months (see column E).

Thank you!

Book1.xlsx
ABCDE
1YearMonthCosts
2202101/01/202167.8243.61419
301/02/202161.25
401/03/202159.19
501/04/202148.36
601/05/202149.97
701/06/202148.36
801/07/202149.97
901/08/202116.12
1001/09/202167
1101/10/202111
1201/11/202144
1301/12/20210
14Total523.04
15202201/01/202254
1601/02/202266
1701/03/202278
1801/04/202268
1901/05/2022-10
2001/06/20220
2101/07/20220
2201/08/202249
2301/09/202227
2401/10/202251
2501/11/20220
2601/12/20220
27Total383
28202301/01/20230
2901/02/20230
3001/03/2023106
3101/04/202396
3201/05/202346
3301/06/2023188
3401/07/20231043.61419
3501/08/202320
3601/09/202330
3701/10/202340
3801/11/202350
3901/12/202360
40Total646
Sheet1
Cell Formulas
RangeFormula
E2E2=AVERAGEIFS(D:D,C:C,"<="&C34)
C14,C40,C27C14=SUM(C2:C13)
D34D34=AVERAGEIFS(C:C,B:B,"<="&B34)
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I think this will work in excel 2021.

MrExcelPlayground19.xlsx
ABCD
1YearMonthCosts
220211/1/202167.82 
32/1/202161.25
43/1/202159.19
54/1/202148.36
65/1/202149.97
76/1/202148.36
87/1/202149.97
98/1/202116.12
109/1/202167
1110/1/202111
1211/1/202144
1312/1/20210
14Total523.04
1520221/1/202254
162/1/202266
173/1/202278
184/1/202268
195/1/2022-10
206/1/20220
217/1/20220
228/1/202249
239/1/202227
2410/1/202251
2511/1/20220
2612/1/20220
27Total383
2820231/1/20230
292/1/20230
303/1/2023106
314/1/202396
325/1/202346
336/1/2023188
347/1/20231043.61419
358/1/2023
369/1/2023
3710/1/2023
3811/1/2023
3912/1/2023
40Total446
Sheet3
Cell Formulas
RangeFormula
D2:D34D2=LET(a,COUNTA(C:C)-2,bb,SEQUENCE(a),c,AVERAGEIFS(C:C,B:B,">1"),IF(bb=a,c,""))
C14,C40,C27C14=SUM(C2:C13)
Dynamic array formulas.
 
Upvote 0
Solution
I think this will work in excel 2021.

MrExcelPlayground19.xlsx
ABCD
1YearMonthCosts
220211/1/202167.82 
32/1/202161.25
43/1/202159.19
54/1/202148.36
65/1/202149.97
76/1/202148.36
87/1/202149.97
98/1/202116.12
109/1/202167
1110/1/202111
1211/1/202144
1312/1/20210
14Total523.04
1520221/1/202254
162/1/202266
173/1/202278
184/1/202268
195/1/2022-10
206/1/20220
217/1/20220
228/1/202249
239/1/202227
2410/1/202251
2511/1/20220
2612/1/20220
27Total383
2820231/1/20230
292/1/20230
303/1/2023106
314/1/202396
325/1/202346
336/1/2023188
347/1/20231043.61419
358/1/2023
369/1/2023
3710/1/2023
3811/1/2023
3912/1/2023
40Total446
Sheet3
Cell Formulas
RangeFormula
D2:D34D2=LET(a,COUNTA(C:C)-2,bb,SEQUENCE(a),c,AVERAGEIFS(C:C,B:B,">1"),IF(bb=a,c,""))
C14,C40,C27C14=SUM(C2:C13)
Dynamic array formulas.
Thank you, JamesCanale! Your formula matches exactly what I need and works perfectly!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,076
Members
453,020
Latest member
mattg2448

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