Running total Last 12 months per category (excluding Zeros)

vipett

New Member
Joined
May 6, 2021
Messages
17
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have a list of purchase prices per month for a large number of articles, I would like to calculate the running 12 months average per article.
I want to exclude zeros, for example if I purchased an article in January for 100 usd, nothing in february, the average price for february should still be 100, until a new purchase is made.
Also for the first 11 months, it should be the running total from the start, i.e January 2021's running total would only be for January 2021, February should be running total January-> February, March would be January-March. etc

Below is a mockup (The previous value (if larger than 0) "lives" and influences the average for 12 months if there is another purchase made, otherwise it lives "forever".

Super happy for all help with this I can get!
ProductMonthPriceAverage L12
A
Jan-21​
0​
0​
A
Feb-21​
0​
0​
A
Mar-21​
0​
0​
A
Apr-21​
0​
0​
A
May-21​
100​
100​
A
Jun-21​
0​
100​
A
Jul-21​
0​
100​
A
Aug-21​
0​
100​
A
Sep-21​
0​
100​
A
Oct-21​
0​
100​
A
Nov-21​
200​
150​
A
Dec-21​
0​
150​
A
Jan-22​
0​
150​
A
Feb-22​
0​
150​
A
Mar-22​
0​
150​
A
Apr-22​
0​
150​
A
May-22​
0​
200​
A
Jun-22​
0​
200​
A
Jul-22​
0​
200​
A
Aug-22​
0​
200​
A
Sep-22​
300​
250​
A
Oct-22​
0​
300​
A
Nov-22​
0​
300​
A
Dec-22​
0​
300​
A
Jan-23​
0​
300​
A
Feb-23​
0​
300​
A
Mar-23​
0​
300​
A
Apr-23​
0​
300​
A
May-23​
0​
300​
A
Jun-23​
0​
300​
A
Jul-23​
0​
300​
B
Jan-21​
0​
0​
B
Feb-21​
0​
0​
B
Mar-21​
0​
0​
B
Apr-21​
0​
0​
B
May-21​
100​
100​
B
Jun-21​
0​
100​
B
Jul-21​
0​
100​
B
Aug-21​
0​
100​
B
Sep-21​
0​
100​
B
Oct-21​
0​
100​
B
Nov-21​
200​
150​
B
Dec-21​
0​
150​
B
Jan-22​
0​
150​
B
Feb-22​
0​
150​
B
Mar-22​
0​
150​
B
Apr-22​
0​
150​
B
May-22​
0​
200​
B
Jun-22​
0​
200​
B
Jul-22​
0​
200​
B
Aug-22​
0​
200​
B
Sep-22​
300​
250​
B
Oct-22​
0​
300​
B
Nov-22​
0​
300​
B
Dec-22​
0​
300​
B
Jan-23​
0​
300​
B
Feb-23​
0​
300​
B
Mar-23​
0​
300​
B
Apr-23​
0​
300​
B
May-23​
0​
300​
B
Jun-23​
0​
300​
B
Jul-23​
0​
300​
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
How about
Excel Formula:
=AVERAGE(FILTER(TAKE(C$2:C2,-12),(TAKE(C$2:C2,-12)<>0)*(TAKE(A$2:A2,-12)=A2),0))
 
Upvote 0
Solution
How about
Excel Formula:
=AVERAGE(FILTER(TAKE(C$2:C2,-12),(TAKE(C$2:C2,-12)<>0)*(TAKE(A$2:A2,-12)=A2),0))
Hi,

Thanks!
An addition, is it possible to fill the last values as well?

For example if a purchase happens in Current Month -14, the average price that your formula correctly calculated is shown for -14 to -2, but for month -1 and current month it is zero again, is it possible to fill the last valid value down?
 
Upvote 0
Not sure what you are saying, the formula does fill all values
Fluff.xlsm
ABCD
1ProductMonthPriceAverage L12
2A21-Jan00
3A21-Feb00
4A21-Mar00
5A21-Apr00
6A21-May100100
7A21-Jun0100
8A21-Jul0100
9A21-Aug0100
10A21-Sep0100
11A21-Oct0100
12A21-Nov200150
13A21-Dec0150
14A22-Jan0150
15A22-Feb0150
16A22-Mar0150
17A22-Apr0150
18A22-May0200
19A22-Jun0200
20A22-Jul0200
21A22-Aug0200
22A22-Sep300250
23A22-Oct0250
24A22-Nov0300
25A22-Dec0300
26A23-Jan0300
27A23-Feb0300
28A23-Mar0300
29A23-Apr0300
30A23-May0300
31A23-Jun0300
32A23-Jul0300
33B21-Jan00
34B21-Feb00
35B21-Mar00
36B21-Apr00
37B21-May100100
38B21-Jun0100
39B21-Jul0100
40B21-Aug0100
41B21-Sep0100
42B21-Oct0100
43B21-Nov200150
44B21-Dec0150
45B22-Jan0150
46B22-Feb0150
47B22-Mar0150
48B22-Apr0150
49B22-May0200
50B22-Jun0200
51B22-Jul0200
52B22-Aug0200
53B22-Sep300250
54B22-Oct0250
55B22-Nov0300
56B22-Dec0300
57B23-Jan0300
58B23-Feb0300
59B23-Mar0300
60B23-Apr0300
61B23-May0300
62B23-Jun0300
63B23-Jul0300
Sheet5
Cell Formulas
RangeFormula
D2:D63D2=AVERAGE(FILTER(TAKE(C$2:C2,-12),(TAKE(C$2:C2,-12)<>0)*(TAKE(A$2:A2,-12)=A2),0))
 
Upvote 0
yes in this example, but if you remove the 300 in 22-sep, the figures will end 12 months after previous purchase , I would like the last prevailing average to remain until we get a new price
 
Upvote 0
Ok, how about
Excel Formula:
=LET(f,FILTER(TAKE(C$2:C2,-12),(TAKE(C$2:C2,-12)<>0)*(TAKE(A$2:A2,-12)=A2),""),IF(COUNT(f)=0,XLOOKUP(A2,A$1:A1,D$1:D1,0,0,-1),AVERAGE(f)))
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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