Adjust average formula properly when the table is extended

vladimiratanasiu

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

I have a table that shows the electric power data (period, consumption etc.) of a client. At the end of each year, it is calculated the monthly average of consumption and costs. Since 2022, giving the variation of months with / without consumption, it is included also a progressive average, calculated as mean value of the whole period between the first and the last month with non-zero energy. In our example (cell Q68), progressive average is given by the period January 2022 – October 2022, resulting a total of 383 kW/10 months (they are accounted also the zero consumption months). The issue appeared when I added the year 2023 and tried to adjust in the cells Q87 and R87 formulas from cells Q68 and R68, considering the new references (Q74 and R74). Even if I didn’t add yet new values of year 2023, the cells Q87 and R87 show non-zero results. Which is the right solution in this case and how should I adjust it when add a new similar table in the future (2024, 2025 etc.)?

Thank you!

P.S. The XLBB didn't picked up completly data from my table, keeping blank the rows with number of the years. I attach a photo of one section, if necessary to.
Untitled1.png


Book1
PQR
1Electric power
2
3PeriodKwhValue (including VAT)
4Jan-1978.29129.00
5Feb-1970.720.00
6Mar-1971.48125.40
7Apr-1964.4220.40
8May-1966.570.00
9Jun-1964.4277.97
10Jul-1966.570.00
11Aug-1966.5795.14
12Sep-1966.290.00
13Oct-1969.790.00
14Nov-1967.5473.30
15Dec-1969.7961.67
16Annual total822.45582.88
17Monthly average 68.5448.57
20
33Annual total650.31485.50
34Monthly average 54.1940.46
37
50Annual total523.04464.67
51Monthly average 43.5938.72
54
55Jan-2254.0036.57
56Feb-2266.0044.70
57Mar-2278.0053.04
58Apr-2268.0046.25
59May-22-10.00-7.12
60Jun-22
61Jul-22
62Aug-2249.0033.32
63Sep-2227.0018.13
64Oct-2251.0034.62
65Nov-22
66Dec-22
67Annual total383.00259.51
68Monthly average 38.3025.95
6931.9221.63
73
74Jan-23
75Feb-23
76Mar-23
77Apr-23
78May-23
79Jun-23
80Jul-23
81Aug-23
82Sep-23
83Oct-23
84Nov-23
85Dec-23
86Annual total0.000.00
87Monthly average 5.323.60
880.000.00
Sheet1
Cell Formulas
RangeFormula
Q16:R16,Q86:R86,Q67:R67,Q50:R50,Q33:R33Q16=SUM(Q4:Q15)
Q17:R17,Q51:R51,Q34:R34Q17=Q16/COUNTA(Q4:Q15)
Q68:R68Q68=AVERAGE(--Q55:INDEX(Q1:Q66,LOOKUP(99^99,Q1:Q66,ROW(Q1:Q66))))
Q69:R69,Q88:R88Q69=Q67/12
Q87Q87=AVERAGE(--Q74:INDEX($Q$1:Q85,LOOKUP(99^99,$Q$1:Q85,ROW($Q$1:Q85))))
R87R87=AVERAGE(--R74:INDEX($R$1:R85,LOOKUP(99^99,$R$1:R85,ROW($R$1:R85))))
 
Last edited:
Okay, the title says youre asking for an average formula. But here is a way to count blank or zero value cells in a range of numbers where the start and end points are varied. But it uses XMATCH and I do not know if that is in Excel 2019.

Mr Excel Questions.xlsx
ABC
318
425
515
6
72
810
90
10
114
1219
13
1422
15
16Count Zero and Blank in the range:4
17(Non Numbers)
Counting Zero and Blank Cells
Cell Formulas
RangeFormula
B16B16=COUNT(INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0)):INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0,-1))) -COUNTIFS(INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0)):INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0,-1)),0)
 
Last edited:
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Okay, the title says youre asking for an average formula. But here is a way to count blank or zero value cells in a range of numbers where the start and end points are varied. But it uses XMATCH and I do not know if that is in Excel 2019.

Mr Excel Questions.xlsx
ABC
318
425
515
6
72
810
90
10
114
1219
13
1422
15
16Count Zero and Blank in the range:4
17(Non Numbers)
Counting Zero and Blank Cells
Cell Formulas
RangeFormula
B16B16=COUNT(INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0)):INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0,-1))) -COUNTIFS(INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0)):INDEX(B3:B14,XMATCH(0,(--(ISNUMBER(B3:B14))),0,-1)),0)
Indeed, I can't use your formula because of XMATCH function and it doesn't view the average. On the other hand, it points all zero / blank cells. However, it should count in my case not 4, but only 3 cells, from the range B3:B14. And I need to be taken into consideration the value ranges of year 2023 from my table (B74:B85, C74:C85), solving the mentioned issue.

Book5.xlsx
ABC
1Energy consumption
2
3PeriodKwhValue (including VAT)
4Jan-1978.29129.00
5Feb-1970.720.00
6Mar-1971.48125.40
7Apr-1964.4220.40
8May-1966.570.00
9Jun-1964.4277.97
10Jul-1966.570.00
11Aug-1966.5795.14
12Sep-1966.290.00
13Oct-1969.790.00
14Nov-1967.5473.30
15Dec-1969.7961.67
16Total annual822.45582.88
17Average power consumption /month68.5448.57
18
19
20
21Jan-2069.790.00
22Feb-2065.29103.61
23Mar-2056.510.00
24Apr-2054.2798.02
25May-2056.080.00
26Jun-2054.2760.51
27Jul-2056.080.00
28Aug-2056.0872.24
29Sep-2055.070.00
30Oct-2057.8471.41
31Nov-2055.970.00
32Dec-2013.0679.71
33Total annual650.31485.50
34Average power consumption /month54.1940.46
35
36
37
38Jan-2167.820.00
39Feb-2161.25104.51
40Mar-2159.190.00
41Apr-2148.36100.60
42May-2149.970.00
43Jun-2148.3679.73
44Jul-2149.970.00
45Aug-2116.1280.09
46Sep-2167.000.00
47Oct-2111.0063.77
48Nov-2144.0035.97
49Dec-210.000.00
50Total annual523.04464.67
51Average power consumption /month43.5938.72
52
53
54
55Jan-2254.0036.57
56Feb-2266.0044.70
57Mar-2278.0053.04
58Apr-2268.0046.25
59May-22-10.00-7.12
60Jun-22
61Jul-22
62Aug-2249.0033.32
63Sep-2227.0018.13
64Oct-2251.0034.62
65Nov-22
66Dec-22
67Total annual383.00259.51
68Average power consumption /month38.3025.95
6931.9221.63
70
71
72
73
74Jan-23
75Feb-23
76Mar-23
77Apr-23
78May-23
79Jun-23
80Jul-23
81Aug-23
82Sep-23
83Oct-23
84Nov-23
85Dec-23
86Total annual0.000.00
87Average power consumption /month5.323.60
880.000.00
Sheet1
Cell Formulas
RangeFormula
B16:C16,B86:C86,B67:C67,B50:C50,B33:C33B16=SUM(B4:B15)
B17:C17,B51:C51,B34:C34B17=B16/COUNTA(B4:B15)
B68:C68B68=AVERAGE(--B55:INDEX(B1:B66,LOOKUP(99^99,B1:B66,ROW(B1:B66))))
B69:C69,B88:C88B69=B67/12
B87B87=AVERAGE(--B74:INDEX(B$1:$B85,LOOKUP(99^99,B$1:$C85,ROW(B$1:$C85))))
C87C87=AVERAGE(--C74:INDEX($C$1:C85,LOOKUP(99^99,$C$1:C85,ROW($C$1:C85))))
 
Last edited:
Upvote 0
3? Rows 6,10,13 are blank and Row 9 is zero, why is 4 incorrect?

regarding the calculations for years and such. I really am still confused with your request. You write averages, then counts. My solution provides a count, and if you want to exclude the zeros, just take the last half out of the formula I provided. As far as the year summaries... the formula above would be repeated after each year in whatever calculation that it is used in. You can get the range of values in that formula to do averages and sums.
 
Upvote 0
Sorry for not explaining clearly the row element ...
The row element you are already using is the Lookup function ...
So in cell B87, you can test
=AVERAGE(--B74:INDEX(B1:B86,SUMPRODUCT(MAX((ROW(A1:A86))*(A1:A86<=TODAY())))))
 
Upvote 0
The respective formula is incorrect, because I mentioned as accountable the range between the first and the last non-zero values. In the example of awoohaw is available only the range B3:B14, the blank cell B15 is outside it.
I applied your formula in the cells B87 and C87, changing also the PC time. In these conditions, it works very well. However, when I tried to use it in the cells B68 and C68, it gives the wrong values 31,92 and 21,63, instead of 38,3 and 25,95 as they are in my previous table.
Book5.xlsx
ABC
1Energy consumption
2
3PeriodKwhValue (including VAT)
4Jan-1978.29129.00
5Feb-1970.720.00
6Mar-1971.48125.40
7Apr-1964.4220.40
8May-1966.570.00
9Jun-1964.4277.97
10Jul-1966.570.00
11Aug-1966.5795.14
12Sep-1966.290.00
13Oct-1969.790.00
14Nov-1967.5473.30
15Dec-1969.7961.67
16Total annual822.45582.88
17Average power consumption /month68.5448.57
18
19
20
21Jan-2069.790.00
22Feb-2065.29103.61
23Mar-2056.510.00
24Apr-2054.2798.02
25May-2056.080.00
26Jun-2054.2760.51
27Jul-2056.080.00
28Aug-2056.0872.24
29Sep-2055.070.00
30Oct-2057.8471.41
31Nov-2055.970.00
32Dec-2013.0679.71
33Total annual650.31485.50
34Average power consumption /month54.1940.46
35
36
37
38Jan-2167.820.00
39Feb-2161.25104.51
40Mar-2159.190.00
41Apr-2148.36100.60
42May-2149.970.00
43Jun-2148.3679.73
44Jul-2149.970.00
45Aug-2116.1280.09
46Sep-2167.000.00
47Oct-2111.0063.77
48Nov-2144.0035.97
49Dec-210.000.00
50Total annual523.04464.67
51Average power consumption /month43.5938.72
52
53
54
55Jan-2254.0036.57
56Feb-2266.0044.70
57Mar-2278.0053.04
58Apr-2268.0046.25
59May-22-10.00-7.12
60Jun-22
61Jul-22
62Aug-2249.0033.32
63Sep-2227.0018.13
64Oct-2251.0034.62
65Nov-22
66Dec-22
67Total annual383.00259.51
68Average power consumption /month31.9221.63
6931.9221.63
70
71
72
73
74Jan-2355.0050.00
75Feb-23
76Mar-2350.0045.00
77Apr-23
78May-23
79Jun-23
80Jul-23
81Aug-23
82Sep-23
83Oct-23
84Nov-23
85Dec-23
86Total annual105.0095.00
87Average power consumption /month35.00
888.757.92
Sheet1
Cell Formulas
RangeFormula
B16:C16,B86:C86,B67:C67,B50:C50,B33:C33B16=SUM(B4:B15)
B17:C17,B51:C51,B34:C34B17=B16/COUNTA(B4:B15)
B68B68=AVERAGE(--B55:INDEX(B1:B67,SUMPRODUCT(MAX((ROW(A1:A67))*(A1:A67<=TODAY())))))
C68C68=AVERAGE(--C55:INDEX(C1:C67,SUMPRODUCT(MAX((ROW(A1:A67))*(A1:A67<=TODAY())))))
B69:C69,B88:C88B69=B67/12
B87B87=AVERAGE(--B74:INDEX(B1:B86,SUMPRODUCT(MAX((ROW(A1:A86))*(A1:A86<=TODAY())))))
 
Last edited:
Upvote 0
3? Rows 6,10,13 are blank and Row 9 is zero, why is 4 incorrect?

regarding the calculations for years and such. I really am still confused with your request. You write averages, then counts. My solution provides a count, and if you want to exclude the zeros, just take the last half out of the formula I provided. As far as the year summaries... the formula above would be repeated after each year in whatever calculation that it is used in. You can get the range of values in that formula to do averages and sums.
I posted by mystake a part of the answer for you in that for James 006. The respective formula is incorrect, because I mentioned as accountable the range between the first and the last non-zero values. In your example is available only the range B3:B14, the blank cell B15 is outside it. So, the formula must point only 3 blank / zero cells. Regarding the count, I didn't mention it as the final result / formula, but as a condition to be taken in consideration, necessary to identify the number of eligible months when structuring the average. And the average must generate the final desired result.
 
Upvote 0
Sorry for not explaining clearly the row element ...
The row element you are already using is the Lookup function ...
So in cell B87, you can test
=AVERAGE(--B74:INDEX(B1:B86,SUMPRODUCT(MAX((ROW(A1:A86))*(A1:A86<=TODAY())))))
Sorry, but I posted by mistake in the body of the last answer for you a part of the message addressed to another member. Please consider only its content that points your formula. Thank you!
 
Upvote 0
I posted by mystake a part of the answer for you in that for James 006. The respective formula is incorrect, because I mentioned as accountable the range between the first and the last non-zero values. In your example is available only the range B3:B14, the blank cell B15 is outside it. So, the formula must point only 3 blank / zero cells. Regarding the count, I didn't mention it as the final result / formula, but as a condition to be taken in consideration, necessary to identify the number of eligible months when structuring the average. And the average must generate the final desired result.
I dont understand why you are considering my row 15 in these discussions. I did not use that in any of my formulas. I did however find another error in my work when the DEC value is zero or blank. I will be doing my debugging with your data. Please tell me in plain language if you want an average for the year for the months that have values. Or do you always want the average to be divided by 12.
 
Upvote 0
I dont understand why you are considering my row 15 in these discussions. I did not use that in any of my formulas. I did however find another error in my work when the DEC value is zero or blank. I will be doing my debugging with your data. Please tell me in plain language if you want an average for the year for the months that have values. Or do you always want the average to be divided by 12.
1. "3? Rows 6,10,13 are blank and Row 9 is zero, why is 4 incorrect?" I answered specifically to this question, where you mentioned clearly the fourth non-zero row / cell. 2. As you see, I wrote specifically in more of my previous messages that the average formula should address the range between the first non-zero to the last non-zero cells, covering them and those blank / with zero values too, from that range. This fact was pointed also in the results of my initial formulas (383/10 months - they are counted also those without values = 38,3). If you notice, in my original table there are the cells B69 and C69. They have formulas, shown under the table, that divide the total to 12 months with clear results, but are totally distinct from the yellow ones that I am interested for (B87, C87 vs. B68, C68).
 
Last edited:
Upvote 0
1. "3? Rows 6,10,13 are blank and Row 9 is zero, why is 4 incorrect?" I answered specifically to this question, where you mentioned clearly the fourth non-zero row / cell. 2. As you see, I wrote specifically in more of my previous messages that the average formula should address the range between the first non-zero to the last non-zero cells, covering them and those blank / with zero values too, from that range. This fact was pointed also in the results of my initial formulas (383/10 months - they are counted also those without values = 38,3). If you notice, in my original table there are the cells B69 and C69. They have formulas, shown under the table, that divide the total to 12 months with clear results, but are totally distinct from the yellow ones that I am interested for (B87, C87 vs. B68, C68).
I'm sorry, I do not understand what your requirement is.

I was under the impression you wanted averages or counts for the 12 months in each yearly section.
If that is the case the only thing I want to know is if you want to include months with blank/zero amounts in the denominator.
 
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,334
Members
449,155
Latest member
ravioli44

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