Forum Discussion
Weighted average price over the time | Recursive Measure
Hi everyone,
I have a table that summarizes my data per product type, date, quantity purchased, average price of purchasing, quantity sold, average price of sales and quantity balance. I would like create a measure that in anyway self-reference itself to calculate the average price of quantity balance over the time.
I have the following sample data example in Excel:
G12= ((F12-B12)*G11+(B12*C12))/F12
Measure:= [(200-100)*25,27 + 100*25,07] / 200
I'm strugling to performa a measure like that so I would really appreciate your help 🙂
| Row/Col | A | B | C | D | E | F | G |
| 1 | QTY Pur | Avg Pur | QTY Sal | Avg Sal | Balance | Measure | |
| 2 | A | 300 | 10,21 | 300 | 10,32 | 0 | 0,00 |
| 3 | 01/01/2020 | 100 | 10,25 | 0 | 0,00 | 100 | 10,25 |
| 4 | 16/01/2020 | 200 | 10,19 | 0 | 0,00 | 300 | 10,21 |
| 5 | 28/01/2020 | 0 | 10,15 | 0 | 10,25 | 300 | 10,21 |
| 6 | 04/02/2020 | 0 | 10,35 | 100 | 10,30 | 200 | 10,21 |
| 7 | 21/02/2020 | 0 | 0 | 200 | 10,40 | 0 | 0,00 |
| 8 | B | 500 | 25,21 | 200 | 25,27 | 300 | 25,16 |
| 9 | 01/01/2020 | 200 | 25,31 | 0 | 0,00 | 200 | 25,31 |
| 10 | 16/01/2020 | 100 | 25,2 | 0 | 0,00 | 300 | 25,27 |
| 11 | 28/01/2020 | 0 | 0 | 200 | 25,27 | 100 | 25,27 |
| 12 | 04/02/2020 | 100 | 25,07 | 0 | 0,00 | 200 | 25,17 |
| 13 | 21/02/2020 | 100 | 25,15 | 0 | 0,00 | 300 | 25,16 |
| 14 | C | 600 | 17,95 | 200 | 18,03 | 400 | 17,95 |
| 15 | 01/01/2020 | 300 | 17,93 | 0 | 0,00 | 300 | 17,93 |
| 16 | 16/01/2020 | 0 | 0 | 100 | 18,01 | 200 | 17,93 |
| 17 | 28/01/2020 | 0 | 0 | 100 | 18,05 | 100 | 17,93 |
| 18 | 21/02/2020 | 300 | 17,96 | 0 | 0,00 | 400 | 17,95 |
| 19 | D | 500 | 5,94 | 0 | 6,10 | 500 | 5,93 |
| 20 | 01/01/2020 | 100 | 5,98 | 0 | 0,00 | 100 | 5,98 |
| 21 | 16/01/2020 | 100 | 5,9 | 0 | 0,00 | 200 | 5,94 |
| 22 | 28/01/2020 | 100 | 5,86 | 0 | 0,00 | 300 | 5,91 |
| 23 | 04/02/2020 | 100 | 5,89 | 0 | 0,00 | 400 | 5,91 |
| 24 | 21/02/2020 | 100 | 6,01 | 0 | 0,00 | 500 | 5,93 |
| 25 | Total | 1900 | 14,38 | 700 | 14,05 | 1200 |
2 Replies
- lbendlin
Super User
What is the formula for G9? Fx -Bx is the previous balance, so F12-B12 is the same as F11 ?
- heitorodriguessRegular Visitor
Hello lbendlin
The general formula would be the following:
[(Balance - QTY Pur) * Previous Measure Value for that Item + (QTY Pur * AvgPur)] / Balance
For G9 as there is no previous measure value for Item B, would be only (QTY Pur * AvgPur)] / Balance:
(200*25,31)/200=25,31
Fx - Bx is equal the previous balance only in case there is no QTY Sal
I hope now it´s more clear.
Thanks in advance!