Formula to calculate dinamically the average costs until the last non-blank cell

vladimiratanasiu

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

I have a large table with monthly spendings. Some months they still don't happen, so that the correspondent cells are empty. I need a formula to calculate dinamically the average incurred costs until the last period with value, but counting also the previous months without spendings (see the results from column C).

Thank you!

Book1
ABC
1MonthEuroAverage
2Jan-2236.5736.57
3Feb-2244.7040.635
4Mar-22
5Apr-2246.2531.88
6May-22-7.1224.08
7Jun-22
8Jul-22
9Aug-2233.3219.215
10Sep-22
11Oct-22
12Nov-2214.3615.28
13Dec-22
14Average
Sheet1
Cell Formulas
RangeFormula
C2C2=B2/1
C3C3=SUM(B2:B3)/2
C5C5=SUM(B2:B5)/4
C6C6=SUM(B2:B6)/5
C9C9=SUM(B2:B9)/8
C12C12=SUM(B2:B12)/11
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Instead of using this -
Excel Formula:
=SUM(B2:B3)/2

Use this from C2 itself and fill down

Excel Formula:
=SUM($B$2:B2)/COUNTA($B$2:B2)

And if that does not counts blank cells then use

Excel Formula:
=SUM($B$2:B2)/(COUNTA($B$2:B2)+COUNTBLANK($B$2:B2))

That shall work. Try it.

Making First cell B2 absolute and later B2 relative makes formula dynamic.
 
Upvote 0
Another option
Excel Formula:
=IF(B2="","",AVERAGE(--B$2:B2))
 
Upvote 0
Thank you, Fluff and SanjayGulatiMusafir, for your responses!

I think that both formulas covers only partially my needs, the final solution looking like a combination between them. The numbers inserted in the column C of my table are only for examples of the desired values. I wish the result be only a final / single, not more succesive ones, and placed in the cell C14. It should reflect the progressive value, reached from the first non-blank cell (B2) to the next similar one (B3,B5 etc.), but including in the calculation the empty ones between them. So, the formula should relate to a dynamic range (B2:B3, B2:B5 etc), extending automatically, not manually, the references to the new non-empty cell.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Thank you, Fluff and SanjayGulatiMusafir, for your responses!

I think that both formulas covers only partially my needs, the final solution looking like a combination between them. The numbers inserted in the column C of my table are only for examples of the desired values. I wish the result be only a final / single, not more succesive ones, and placed in the cell C14. It should reflect the progressive value, reached from the first non-blank cell (B2) to the next similar one (B3,B5 etc.), but including in the calculation the empty ones between them. So, the formula should relate to a dynamic range (B2:B3, B2:B5 etc), extending automatically, not manually, the references to the new non-empty cell.
Let me understand - You want average in Cell C14 from B2 to the cell in Column B that corresponds to the current month. Right or is it something different?
 
Upvote 0
You edited your post after I saw it, which is why I responded as I did.
 
Upvote 0
What are you expecting for the result, 15.28, 14 or something else?
 
Upvote 0
Let me understand - You want average in Cell C14 from B2 to the cell in Column B that corresponds to the current month. Right or is it something different?
Exactly, considering it just an example. However, the formula references shouldn't refer to the whole month / larger period, but only to the area between the first and last non-empty cell. And as the values are added progressively, the formula should become a dynamic one, to cover the new non-blank cells too.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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