Forum Discussion
Moving average / moving variance
- Anonymous6 years ago
You are mixing 2 different measures. One is the 12-month average and the other is the sum of the 12-month averages. If you want to have these 2 morphed into one... then you'll need to write a SWITCH which will select the measure based on what time period is in scope.
Actually... on reflection, you can do something simpler: you can write a measure that will sum up the averages over the currently visible pieces of time. If you never go below the month level, then it's even easier. Hide the individual dates so that they can't be selected, leave only pieces of time from the month up and write:
sumx(
VALUES ( Calendar[YearMonth] ),[12M Average]
)
This will give you what you want.
Best
D
Hi,
maybe the term "moving average" is misleading or even wrong here. I'll try to illustrate what I want to have with a simple Excel example:
Imagine I have raw data per month. The 12M-moving average for January 2020 (=C14) is AVERAGE(B2:B13). [or maybe Average(B3:B14, if you take the new value into the timeframe, there are varying definitions I guess]
With this formula, I can calculate the moving average for every month after the 12th.
Now as long as I display this measure on the month level, everything is fine, I can simply display the calculated values without any further aggregation.
But if I choose to aggregate on the year level (or quarter, whatever), then I have to take the SUM of all the values in column C, not their average!
If I create a Pivot Table in Excel, this is exactly what happens. But I don't know how to achieve the same behaviour in PowerBI.
You are mixing 2 different measures. One is the 12-month average and the other is the sum of the 12-month averages. If you want to have these 2 morphed into one... then you'll need to write a SWITCH which will select the measure based on what time period is in scope.
Actually... on reflection, you can do something simpler: you can write a measure that will sum up the averages over the currently visible pieces of time. If you never go below the month level, then it's even easier. Hide the individual dates so that they can't be selected, leave only pieces of time from the month up and write:
sumx(
VALUES ( Calendar[YearMonth] ),
[12M Average]
)
This will give you what you want.
Best
D
- IMett6 years agoHelper III
That looks good, thank you!
Although it didn't solve my intiial question on how to calculate the moving variance, accordingly, without having to write the variance formula explicitly. I hoped to find a way to calculate the desired moving average by using the function Averagex and adapt the filter settings to a different measure with the VARX.P function.