Progressive average formula that counts also blank cells

vladimiratanasiu

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

I posted a message some time ago (Formula to calculate automatically progressive average), getting the proper solution in that case. Basically, it calculates and shows automatically the average of all costs at some point, each time a new value is inserted and excluding the annual totals. Presently, some changes have occured, needing to adjust the old formula to the new conditions. In the attached table, the column D includes cells to show monthly energy consumption. Some cells contains non-zero values (e.g. D2:D12, D15:D19 etc.), but other ones are blank (e.g. D13, D20:D21 etc.). In column F, it's calculated the medium energy consumption, as dynamic average of all values recorded at some point. However, the formula considers only non-zero cells (see results from F13, F20:F21, F28:F29 etc.), ignoring the blank ones. I need it to be adjusted, so that can count also the blank cells, generating in column F the average values from the column J. As it's seen, the range J2:J11 has identical values with those from D2:D11, but starting with J13 there are constant differences between the cells of the two columns because of the blank cells from column D. In addition, I need the formula to take into consideration all cells after the last non-zero one (e.g. F43:F52), so that they can be blank and not show average values calculated on the basis of the according range of column D (D43:D52).

Thank you!

2024.xlsx
BCDFJ
1YearMonthMonthly energy consumption (Kwh)
22021Jan-2167.8267.8267.82
3Feb-2161.2564.5464.54
4Mar-2159.1962.7562.75
5Apr-2148.3659.1659.16
6May-2149.9757.3257.32
7Jun-2148.3655.8355.83
8Jul-2149.9754.9954.99
9Aug-2116.1250.1350.13
10Sep-216752.0052.00
11Oct-211147.9047.90
12Nov-214447.5547.55
13Dec-21 47.5543.59
14Total523.04 
152022Jan-225448.0944.39
16Feb-226649.4645.93
17Mar-227851.5048.07
18Apr-226852.6049.32
19May-22-1048.6945.83
20Jun-22 48.6943.28
21Jul-22 48.6941.00
22Aug-224948.7141.40
23Sep-222747.5040.72
24Oct-225147.6941.18
25Nov-22 47.6939.39
26Dec-22 47.6937.75
27Total383 
282023Jan-23 47.6936.24
29Feb-23 47.6934.85
30Mar-2310650.6037.48
31Apr-239652.7639.57
32May-234652.4639.79
33Jun-2318858.3544.73
34Jul-23 58.3543.29
35Aug-2313961.7146.28
36Sep-235261.3246.46
37Oct-2310963.1648.30
38Nov-234162.3348.09
39Dec-234661.7548.03
40Total823 
412024Jan-246261.7648.41
42Feb-245561.5348.58
43Mar-24 61.53blank / no value
44Apr-24 61.53blank / no value
45May-24 61.53blank / no value
46Jun-24 61.53blank / no value
47Jul-24 61.53blank / no value
48Aug-24 61.53blank / no value
49Sep-24 61.53blank / no value
50Oct-24 61.53blank / no value
51Nov-24 61.53blank / no value
52Dec-24 61.53blank / no value
53Total117
Energy consumption
Cell Formulas
RangeFormula
C2:C13C2='Costuri energie generale'!P38
C15:C26C15='Costuri energie generale'!P55
C28:C39C28='Costuri energie generale'!P74
C41:C52C41='Costuri energie generale'!P93
F2:F52F2=IF((C2="total"),"",AVERAGEIFS($D$2:D2,$C$2:C2,"<>"&"Total"))
D2:D13D2=IF(ISBLANK('Costuri energie generale'!Q38),"",'Costuri energie generale'!Q38)
D14,D53,D40,D27D14=SUM(D2:D13)
D15:D26D15=IF(ISBLANK('Costuri energie generale'!Q55),"",'Costuri energie generale'!Q55)
D28:D39D28=IF(ISBLANK('Costuri energie generale'!Q74),"",'Costuri energie generale'!Q74)
D41:D52D41=IF(ISBLANK('Costuri energie generale'!Q93),"",'Costuri energie generale'!Q93)
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi

Try

In Cell F2 enter : =IF(C4="Total","",SUM(AVERAGE(IF((C$4:C4<>"Total"),1*(D$4:D4))))) and drag down
 
Upvote 0
Hi

Try

In Cell F2 enter : =IF(C4="Total","",SUM(AVERAGE(IF((C$4:C4<>"Total"),1*(D$4:D4))))) and drag down
Thank you for your response! I used your formula, getting the attached results. Unfortunately, there are errors exactly in the cells related with the blank ones. And the results are similar with the original values, but I need them to show an average value (column F), as I mentioned in my original message. What is the proper solution? Thank you!
2024.xlsx
BCDEF
1YearMonthMonthly energy consumption (Kwh)Medium monthly energy consumption (Kwh)
22021Jan-2167.8267.8267.82
3Feb-2161.2564.5461.25
4Mar-2159.1962.7559.19
5Apr-2148.3659.1648.36
6May-2149.9757.3249.97
7Jun-2148.3655.8348.36
8Jul-2149.9754.9949.97
9Aug-2116.1250.1316.12
10Sep-216752.0067.00
11Oct-211147.9011.00
12Nov-214447.5544.00
13Dec-2147.55#VALUE!
14Total523.04  
152022Jan-225448.0954.00
16Feb-226649.4666.00
17Mar-227851.5078.00
18Apr-226852.6068.00
19May-22-1048.69-10.00
20Jun-2248.69#VALUE!
21Jul-2248.69#VALUE!
22Aug-224948.7149.00
23Sep-222747.5027.00
24Oct-225147.6951.00
25Nov-2247.69#VALUE!
26Dec-2247.69#VALUE!
27Total383  
282023Jan-2347.69#VALUE!
29Feb-2347.69#VALUE!
30Mar-2310650.60106.00
31Apr-239652.7696.00
32May-234652.4646.00
33Jun-2318858.35188.00
34Jul-2358.35#VALUE!
35Aug-2313961.71139.00
36Sep-235261.3252.00
37Oct-2310963.16109.00
38Nov-234162.3341.00
39Dec-234661.7546.00
40Total823  
Sheet1
Cell Formulas
RangeFormula
E2:E40E2=IF((C2="total"),"",AVERAGEIFS($D$2:D2,$C$2:C2,"<>"&"Total"))
F2:F40F2=IF(C2="Total","",SUM(AVERAGE(IF((C$2:C2<>"Total"),1*(D$2:D2)))))
D14,D40,D27D14=SUM(D2:D13)
 
Upvote 0
In F3 copied down.
Excel Formula:
=AVERAGEIFS($D$3:$D3,$C$3:$C3,"<>"&"Total",$D$3:$D3,"<>""")
I adjusted your formula to my table, but the results from the range F13:F52 are the same with the values from my original table. I need them to reflect the right average, counting in the calculations the blank cells, too. At the same time, the cells F14, F27, F40 and F43:F52 should contain no value. Could you modify your formula, in order to meet my specific needs? Thank you!

2024.xlsx
BCDEF
1YearMonthMonthly energy consumption (Kwh)Medium monthly energy consumption (Kwh)
22021Jan-2167.8267.8267.82
3Feb-2161.2564.5464.54
4Mar-2159.1962.7562.75
5Apr-2148.3659.1659.16
6May-2149.9757.3257.32
7Jun-2148.3655.8355.83
8Jul-2149.9754.9954.99
9Aug-2116.1250.1350.13
10Sep-216752.0052.00
11Oct-211147.9047.90
12Nov-214447.5547.55
13Dec-2147.5547.55
14Total523.04 47.55
152022Jan-225448.0948.09
16Feb-226649.4649.46
17Mar-227851.5051.50
18Apr-226852.6052.60
19May-22-1048.6948.69
20Jun-2248.6948.69
21Jul-2248.6948.69
22Aug-224948.7148.71
23Sep-222747.5047.50
24Oct-225147.6947.69
25Nov-2247.6947.69
26Dec-2247.6947.69
27Total383 47.69
282023Jan-2347.6947.69
29Feb-2347.6947.69
30Mar-2310650.6050.60
31Apr-239652.7652.76
32May-234652.4652.46
33Jun-2318858.3558.35
34Jul-2358.3558.35
35Aug-2313961.7161.71
36Sep-235261.3261.32
37Oct-2310963.1663.16
38Nov-234162.3362.33
39Dec-234661.7561.75
40Total823 61.75
412024Jan-246261.7661.76
42Feb-245561.5361.53
43Mar-2461.5361.53
44Apr-2461.5361.53
45May-2461.5361.53
46Jun-2461.5361.53
47Jul-2461.5361.53
48Aug-2461.5361.53
49Sep-2461.5361.53
50Oct-2461.5361.53
51Nov-2461.5361.53
52Dec-2461.5361.53
53Total117
Sheet1
Cell Formulas
RangeFormula
E2:E52E2=IF((C2="total"),"",AVERAGEIFS($D$2:D2,$C$2:C2,"<>"&"Total"))
F2F2=AVERAGEIFS($D2:$D$2,$C2:$C$2,"<>"&"Total",$D2:$D$2,"<>""")
F3:F52F3=AVERAGEIFS($D$2:$D3,$C$2:$C3,"<>"&"Total",$D$2:$D3,"<>""")
D14,D53,D40,D27D14=SUM(D2:D13)
 
Upvote 0
Do you want the result in column J. I am not clear. Can you explain more clearly.
I mentioned in my first message that I need a formula to generate the results inserted in the column J of my first table. Each one of them is calculated as an average of all values recorded from January 2021 to that month. But when dividing the sum resulted in that month, it's necessary to be counted also the previous months with no values (e.g. E13, E20, E21 etc), and including them as elements of the average. The original formulas from column F of the initial table makes those calculations, but doesn't consider the blank cells of column D as a dividing element / factor. That's why, in the cells of column F that are in line with the blank cells of column D (e.g. F13, F20, F21 etc.) formula repeats the results generated in the last cell that has a non-zero equivalent cell in column D (in our case, F13 and F19). I need also, as in the original formula, the new one to ignore the cells that summarize all values from one year (D14, D27, D40), and keep blank the cells of column E from that row (E14, E27, E40). Could you help me in this sense? Thank you!
 
Upvote 0
In K3 copied down
Excel Formula:
=IF(OR($C3="Total",SUMIF($C3:$C$54,"<>"&"Total",$D3:$D$54)=0),"",SUMPRODUCT($D$3:$D3*($C$3:$C3<>"Total"))/SUMPRODUCT(1*($C$3:$C3<>"Total")))
 
Upvote 0
In K3 copied down
Excel Formula:
=IF(OR($C3="Total",SUMIF($C3:$C$54,"<>"&"Total",$D3:$D$54)=0),"",SUMPRODUCT($D$3:$D3*($C$3:$C3<>"Total"))/SUMPRODUCT(1*($C$3:$C3<>"Total")))
Thank you for the answer. I tried your formula, exactly as you mentioned. Unfortunately, I've got some wrong values and errors. I attached to this answer a table, that includes column L. It contains the desired results and the simple formulas used to get each one them. Where is mentioned "BLANK", I need that cell to contain formula but show no value. Could you / someone else help me, in this sense?

Thank you!

2024.xlsx
BCDEKLM
1YearMonthMonthly energy consumption (Kwh)Medium monthly energy consumption (Kwh)Necessary results
22021Jan-2167.8267.8267.82
3Feb-2161.2564.5461.2564.54
4Mar-2159.1962.7560.2262.75
5Apr-2148.3659.1656.2759.16
6May-2149.9757.3254.6957.32
7Jun-2148.3655.8353.4355.83
8Jul-2149.9754.9952.8554.99
9Aug-2116.1250.1347.6050.13
10Sep-216752.0050.0352.00
11Oct-211147.9045.6947.90
12Nov-214447.5545.5247.55
13Dec-2147.55#VALUE!43.59
14Total523.04  BLANK
152022Jan-225448.09#VALUE!44.39
16Feb-226649.46#VALUE!45.93
17Mar-227851.50#VALUE!48.07
18Apr-226852.60#VALUE!49.32
19May-22-1048.69#VALUE!45.83
20Jun-2248.69#VALUE!43.28
21Jul-2248.69#VALUE!41.00
22Aug-224948.71#VALUE!42.75
23Sep-222747.50#VALUE!43.14
24Oct-225147.69#VALUE!41.18
25Nov-2247.69#VALUE!39.39
26Dec-2247.69#VALUE!37.75
27Total383  BLANK
282023Jan-2347.69#VALUE!36.24
29Feb-2347.69#VALUE!34.85
30Mar-2310650.60#VALUE!37.48
31Apr-239652.76#VALUE!
32May-234652.46#VALUE!
33Jun-2318858.35#VALUE!
34Jul-2358.35#VALUE!
35Aug-2313961.71#VALUE!
36Sep-235261.32#VALUE!
37Oct-2310963.16#VALUE!
38Nov-234162.33#VALUE!
39Dec-234661.75#VALUE!
40Total823  BLANK
412024Jan-246261.76#VALUE!48.41
42Feb-245561.53#VALUE!48.58
43Mar-24 47.33, but Blank cell
44Apr-24 46.15, but Blank cell
45May-24 , but Blank cell
46Jun-24 , but Blank cell
47Jul-24 , but Blank cell
48Aug-24 , but Blank cell
49Sep-24 , but Blank cell
50Oct-24 , but Blank cell
51Nov-24 , but Blank cell
52Dec-24 , but Blank cell
53Total117BLANK
Sheet1
Cell Formulas
RangeFormula
L2L2=D2/1
L3L3=SUM(D2:D3)/2
L4L4=SUM(D2:D4)/3
L5L5=SUM(D2:D5)/4
L6L6=SUM(D2:D6)/5
L7L7=SUM(D2:D7)/6
L8L8=SUM(D2:D8)/7
L9L9=SUM(D2:D9)/8
L10L10=SUM(D2:D10)/9
L11L11=SUM(D2:D11)/10
L12L12=SUM(D2:D12)/11
L13L13=SUM(D2:D13)/12
D14,D53,D40,D27D14=SUM(D2:D13)
L15L15=SUM(D2:D13,D15)/13
L16L16=SUM(D2:D13,D15:D16)/14
L17L17=SUM(D2:D13,D15:D17)/15
L18L18=SUM(D2:D13,D15:D18)/16
L19L19=SUM(D2:D13,D15:D19)/17
L20L20=SUM(D2:D13,D15:D20)/18
L21L21=SUM(D2:D13,D15:D21)/19
L22L22=SUM(D2:D13,D15:D23)/20
L23L23=SUM(D2:D13,D15:D24)/21
L24L24=SUM(D2:D13,D15:D25)/22
L25L25=SUM(D2:D13,D15:D26)/23
L26L26=SUM(D2:D13,D15:D26)/24
L28L28=SUM(D2:D13,D15:D26,D28)/25
L29L29=SUM(D2:D13,D15:D26,D28:D29)/26
L30L30=SUM(D2:D13,D15:D26,D28:D30)/27
E2:E42E2=IF((C2="total"),"",AVERAGEIFS($D$2:D2,$C$2:C2,"<>"&"Total"))
L41L41=SUM(D2:D13,D15:D26,D28:D39,D41)/37
L42L42=SUM(D2:D13,D15:D26,D28:D39,D41:D42)/38
L43L43=SUM(D2:D13,D15:D26,D28:D39,D41:D43)/39
L44L44=SUM(D2:D13,D15:D26,D28:D39,D41:D44)/40
K3:K52K3=IF(OR($C3="Total",SUMIF($C3:$C$54,"<>"&"Total",$D3:$D$54)=0),"",SUMPRODUCT($D$3:$D3*($C$3:$C3<>"Total"))/SUMPRODUCT(1*($C$3:$C3<>"Total")))
 
Upvote 0

Forum statistics

Threads
1,223,915
Messages
6,175,354
Members
452,638
Latest member
Oluwabukunmi

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