Create Running Weighted Average
Combine ROW_NUMBER, self JOIN, and CASE WHEN for that
The "normal" running average gives equal weight to all data points, regardless of how recent they are.
To give more weight to recent data, use running weighted average.
π FORMULA: π πππππππ_πππ_πππππππ = πππ ππ (πππππππ * π πππππ), where π πππππ is a value from 0 to 1.
For example, to give 80% weight to the most recent data point and 20% weight to the data point before that, you can use:
π πππππππ_πππ_πππππππ = πΆ.πΎ * πππππππ + πΆ.πΈ * πππππππ
π STEPS:
1οΈβ£ Use ππΎπ_π½ππΌπ±π΄π to assign a number to each row in the dataset. (One row = one year)
2οΈβ£ Perform a ππ΄π»π΅ πΉπΎπΈπ½ so that the past year's data and the current year's data appear in the same row.
2οΈβ£ Use a π²π°ππ΄ ππ·π΄π½(πππΌ) to assign weights to the past year's data.
This works on all flavors of SQL!