Adjust formula of dynamic average

vladimiratanasiu

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

I posted some weeks ago a message regarding a dynamic formula of monthly costs, getting in the answer Formula to calculate dynamic average of monthly costs a good solution adapted to the conditions at that time. Shortely, it calculates dinamically (see value from D88) the average of all monthly values , excepting the annually totals and moving down in line with the each new number inserted. If I add the new values manually, the formula works according to my needs. The problem is when my monthly cells are linked by formulas with data from another table (see F51:F88) and the values are imported automatically from it. In our example, the cells from C85:C88 are linked with those from F85:F88, but the last ones have no content yet. In these conditions, the cells C85:C88 show value 0 / blank space, and the average (D88) is calculated and moves automatically in line with the last cell (C88). My question is how could be adjusted the given formula, so that the right result (e.g. value from E84) can be shown progressively in line only with the last cell (e.g. C84) related with real data from the source table , and can avoid in calculation the next ones (C85:C88) that have no equivalent numerical in the source range.

Thank you!

Book1.xlsx
ABCDEF
1YearMonthCosts
22017Apr-1734.83 34.83
3May-177272
4Jun-1774.7774.77
5Jul-1777.7477.74
6Aug-1776.576.5
7Sep-1767.7467.74
8Oct-17130.11130.11
9Nov-17183.44183.44
10Dec-17189.56189.56
11Total906.69
122018Jan-18189.56189.56
13Feb-18169.62169.62
14Mar-18177.41177.41
15Apr-18128.08128.08
16May-18132.35132.35
17Jun-18128.08128.08
18Jul-18132.35132.35
19Aug-18132.35132.35
20Sep-18113.2113.2
21Oct-1878.2978.29
22Nov-1875.7775.77
23Dec-1878.2978.29
24Total1535.35
252019Jan-1978.2978.29
26Feb-1970.7270.72
27Mar-1971.4871.48
28Apr-1964.4264.42
29May-1966.5766.57
30Jun-1964.4264.42
31Jul-1966.5766.57
32Aug-1966.5766.57
33Sep-1966.2966.29
34Oct-1969.7969.79
35Nov-1967.5467.54
36Dec-1969.7969.79
37Total822.45
382020Jan-2069.7969.79
39Feb-2065.2965.29
40Mar-2056.5156.51
41Apr-2054.2754.27
42May-2056.0856.08
43Jun-2054.2754.27
44Jul-2056.0856.08
45Aug-2056.0856.08
46Sep-2055.0755.07
47Oct-2057.8457.84
48Nov-2055.9755.97
49Dec-2013.0613.06
50Total650.31
5120211/1/202167.8267.82
522/1/202161.2561.25
533/1/202159.1959.19
544/1/202148.3648.36
555/1/202149.9749.97
566/1/202148.3648.36
577/1/202149.9749.97
588/1/202116.1216.12
599/1/20216767
6010/1/20211111
6111/1/20214444
6212/1/202100
63Total523.04
6420221/1/20225454
652/1/20226666
663/1/20227878
674/1/20226868
685/1/2022-10-10
696/1/202200
707/1/202200
718/1/20224949
729/1/20222727
7310/1/20225151
7411/1/202200
7512/1/202200
76Total383
7720231/1/202300
782/1/202300
793/1/2023106106
804/1/20239696
815/1/20234646
826/1/2023188188
837/1/202300
848/1/202313970.07584139
859/1/20230
8610/1/20230
8711/1/20230
8812/1/2023066.61531
89Total575
Sheet1
Cell Formulas
RangeFormula
D2:D88D2=LET(a,COUNTA(C:C)-2,bb,SEQUENCE(a),c,AVERAGEIFS(C:C,B:B,">1"),IF(bb=a,c,""))
C2:C10,C12:C23,C25:C36,C38:C49,C51:C62,C64:C75,C77:C88C2=F2
C11C11=SUM(C2:C10)
C24,C37,C50,C63,C76,C89C24=SUM(C12:C23)
Dynamic array formulas.
 
Last edited:

vladimiratanasiu's post #8


I posted a suggestion that you could try. It does not appear that you tried the suggestion Excel Data Subtotal.
I did not state that it was dynamic. If you structure your information correctly, it can yield correct answers quite easily and efficiently.

Hopefully, JamesCanale and/or someone else will provide the formulas that you need.
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
So this will find the highest date in "Sheet 1" (for my thing, it's just whats in rows N and O), and put the running average of everything in column C - even stuff before the earliest part of Sheet 1.

MrExcelPlayground20.xlsx
ABCDEFGHIJKLMNOP
1YearMonthCostsElectricity
220174/1/201734.83 
35/1/201772PeriodCosts
46/1/201774.771/1/201978.29
57/1/201777.742/1/201970.72
68/1/201776.53/1/201971.48
79/1/201767.744/1/201964.42
810/1/2017130.115/1/201966.57
911/1/2017183.446/1/201964.42
1012/1/2017189.567/1/201966.57
11Total906.698/1/201966.57
1220181/1/2018189.569/1/201966.29
132/1/2018169.6210/1/201969.79
143/1/2018177.4111/1/201967.54
154/1/2018128.0812/1/201969.79
165/1/2018132.35Annual total822.45
176/1/2018128.08
187/1/2018132.35
198/1/2018132.35
209/1/2018113.2
2110/1/201878.291/1/202069.79
2211/1/201875.772/1/202065.29
2312/1/201878.293/1/202056.51
24Total1535.354/1/202054.27
2520191/1/201978.295/1/202056.08
262/1/201970.726/1/202054.27
273/1/201971.487/1/202056.08
284/1/201964.428/1/202056.08
295/1/201966.579/1/202055.07
306/1/201964.4210/1/202057.84
317/1/201966.5711/1/202055.97
328/1/201966.5712/1/202013.06
339/1/201966.29Annual total650.31
3410/1/201969.79
3511/1/201967.54
3612/1/201969.79
37Total822.45
3820201/1/202069.791/1/202167.82
392/1/202065.292/1/202161.25
403/1/202056.513/1/202159.19
414/1/202054.274/1/202148.36
425/1/202056.085/1/202149.97
436/1/202054.276/1/202148.36
447/1/202056.087/1/202149.97
458/1/202056.088/1/202116.12
469/1/202055.079/1/202167
4710/1/202057.8410/1/202111
4811/1/202055.9711/1/202144
4912/1/202013.0612/1/20210
50Total650.31Annual total523.04
5120211/1/202167.82
522/1/202161.25
533/1/202159.19
544/1/202148.36
555/1/202149.971/1/202254
566/1/202148.362/1/202266
577/1/202149.973/1/202278
588/1/202116.124/1/202268
599/1/2021675/1/2022-10
6010/1/2021116/1/20220
6111/1/2021447/1/20220
6212/1/202108/1/202249
63Total523.049/1/202227
6420221/1/20225410/1/202251
652/1/20226611/1/20220
663/1/20227812/1/20220
674/1/202268Annual total383
685/1/2022-10
696/1/20220
707/1/20220
718/1/202249
729/1/202227
7310/1/202251
7411/1/202201/1/20230
7512/1/202202/1/20230
76Total3833/1/2023106
7720231/1/202304/1/202396
782/1/202305/1/202346
793/1/20231066/1/2023188
804/1/2023967/1/20230
815/1/2023468/1/2023139
826/1/20231889/1/2023
837/1/2023010/1/2023
848/1/202313970.0758411/1/2023
859/1/2023012/1/2023
8610/1/20230Annual total575
8711/1/20230
8812/1/20230
89Total575
Sheet2
Cell Formulas
RangeFormula
D2:D84D2=LET(a,MATCH(MAXIFS(N:N,O:O,"<>"),B:B,0)-1,b,SEQUENCE(a),c,AVERAGEIFS(OFFSET(C2,0,0,a),OFFSET(B2,0,0,a),">0"),IF(b=a,c,""))
C11C11=SUM(C2:C10)
O16,C24,C37,C50,C63,C76,C89,O86,O67,O50,O33O16=SUM(O4:O15)
B25:C36B25=N4
B38:C49B38=N21
B51:C62B51=N38
B64:C75B64=N55
B77:C88B77=N74
Dynamic array formulas.
 
Upvote 0
Solution
Another approach
Separate the reporting from the data; this is often on a distinct sheet.
Do not enter anything below the data except real numbers that you want to include in the sum or average.
Use a Dynamic range for the sum and average

T202308a.xlsm
BCDEFG
1DateCostsSumAverage
21-Apr-1734.83Total5,395.8470.08
31-May-1772.002017906.69100.74
41-Jun-1774.7720181,535.35127.95
51-Jul-1777.742019822.4568.54
61-Aug-1776.502020650.3154.19
71-Sep-1767.742021523.0443.59
81-Oct-17130.112022383.0031.92
91-Nov-17183.442023575.0071.88
101-Dec-17189.56
111-Jan-18189.56
121-Feb-18169.62
131-Mar-18177.41
141-Apr-18128.08
151-May-18132.35
161-Jun-18128.08
171-Jul-18132.35
181-Aug-18132.35
191-Sep-18113.20
201-Oct-1878.29
211-Nov-1875.77
221-Dec-1878.29
231-Jan-1978.29
241-Feb-1970.72
251-Mar-1971.48
261-Apr-1964.42
271-May-1966.57
281-Jun-1964.42
291-Jul-1966.57
301-Aug-1966.57
311-Sep-1966.29
321-Oct-1969.79
331-Nov-1967.54
341-Dec-1969.79
351-Jan-2069.79
361-Feb-2065.29
371-Mar-2056.51
381-Apr-2054.27
391-May-2056.08
401-Jun-2054.27
411-Jul-2056.08
421-Aug-2056.08
431-Sep-2055.07
441-Oct-2057.84
451-Nov-2055.97
461-Dec-2013.06
471-Jan-2167.82
481-Feb-2161.25
491-Mar-2159.19
501-Apr-2148.36
511-May-2149.97
521-Jun-2148.36
531-Jul-2149.97
541-Aug-2116.12
551-Sep-2167.00
561-Oct-2111.00
571-Nov-2144.00
581-Dec-210.00
591-Jan-2254.00
601-Feb-2266.00
611-Mar-2278.00
621-Apr-2268.00
631-May-22-10.00
641-Jun-220.00
651-Jul-220.00
661-Aug-2249.00
671-Sep-2227.00
681-Oct-2251.00
691-Nov-220.00
701-Dec-220.00
711-Jan-230.00
721-Feb-230.00
731-Mar-23106.00
741-Apr-2396.00
751-May-2346.00
761-Jun-23188.00
771-Jul-230.00
781-Aug-23139.00
4eee
Cell Formulas
RangeFormula
F2F2=SUM(Costs)
G2G2=AVERAGE(Costs)
F3:F9F3=SUMIFS(Costs,Dates,">="&E3,Dates,"<"&EDATE(E3,12))
G3:G9G3=AVERAGEIFS(Costs,Dates,">="&E3,Dates,"<"&EDATE(E3,12))
 
Upvote 0
So this will find the highest date in "Sheet 1" (for my thing, it's just whats in rows N and O), and put the running average of everything in column C - even stuff before the earliest part of Sheet 1.

MrExcelPlayground20.xlsx
ABCDEFGHIJKLMNOP
1YearMonthCostsElectricity
220174/1/201734.83 
35/1/201772PeriodCosts
46/1/201774.771/1/201978.29
57/1/201777.742/1/201970.72
68/1/201776.53/1/201971.48
79/1/201767.744/1/201964.42
810/1/2017130.115/1/201966.57
911/1/2017183.446/1/201964.42
1012/1/2017189.567/1/201966.57
11Total906.698/1/201966.57
1220181/1/2018189.569/1/201966.29
132/1/2018169.6210/1/201969.79
143/1/2018177.4111/1/201967.54
154/1/2018128.0812/1/201969.79
165/1/2018132.35Annual total822.45
176/1/2018128.08
187/1/2018132.35
198/1/2018132.35
209/1/2018113.2
2110/1/201878.291/1/202069.79
2211/1/201875.772/1/202065.29
2312/1/201878.293/1/202056.51
24Total1535.354/1/202054.27
2520191/1/201978.295/1/202056.08
262/1/201970.726/1/202054.27
273/1/201971.487/1/202056.08
284/1/201964.428/1/202056.08
295/1/201966.579/1/202055.07
306/1/201964.4210/1/202057.84
317/1/201966.5711/1/202055.97
328/1/201966.5712/1/202013.06
339/1/201966.29Annual total650.31
3410/1/201969.79
3511/1/201967.54
3612/1/201969.79
37Total822.45
3820201/1/202069.791/1/202167.82
392/1/202065.292/1/202161.25
403/1/202056.513/1/202159.19
414/1/202054.274/1/202148.36
425/1/202056.085/1/202149.97
436/1/202054.276/1/202148.36
447/1/202056.087/1/202149.97
458/1/202056.088/1/202116.12
469/1/202055.079/1/202167
4710/1/202057.8410/1/202111
4811/1/202055.9711/1/202144
4912/1/202013.0612/1/20210
50Total650.31Annual total523.04
5120211/1/202167.82
522/1/202161.25
533/1/202159.19
544/1/202148.36
555/1/202149.971/1/202254
566/1/202148.362/1/202266
577/1/202149.973/1/202278
588/1/202116.124/1/202268
599/1/2021675/1/2022-10
6010/1/2021116/1/20220
6111/1/2021447/1/20220
6212/1/202108/1/202249
63Total523.049/1/202227
6420221/1/20225410/1/202251
652/1/20226611/1/20220
663/1/20227812/1/20220
674/1/202268Annual total383
685/1/2022-10
696/1/20220
707/1/20220
718/1/202249
729/1/202227
7310/1/202251
7411/1/202201/1/20230
7512/1/202202/1/20230
76Total3833/1/2023106
7720231/1/202304/1/202396
782/1/202305/1/202346
793/1/20231066/1/2023188
804/1/2023967/1/20230
815/1/2023468/1/2023139
826/1/20231889/1/2023
837/1/2023010/1/2023
848/1/202313970.0758411/1/2023
859/1/2023012/1/2023
8610/1/20230Annual total575
8711/1/20230
8812/1/20230
89Total575
Sheet2
Cell Formulas
RangeFormula
D2:D84D2=LET(a,MATCH(MAXIFS(N:N,O:O,"<>"),B:B,0)-1,b,SEQUENCE(a),c,AVERAGEIFS(OFFSET(C2,0,0,a),OFFSET(B2,0,0,a),">0"),IF(b=a,c,""))
C11C11=SUM(C2:C10)
O16,C24,C37,C50,C63,C76,C89,O86,O67,O50,O33O16=SUM(O4:O15)
B25:C36B25=N4
B38:C49B38=N21
B51:C62B51=N38
B64:C75B64=N55
B77:C88B77=N74
Dynamic array formulas.
Thank you very much! I adjusted your formula to my worksheets structure and it works wonderful!
 
Upvote 0
Thank you very much! I adjusted your formula to my worksheets structure and it works wonderful!
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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