Forum Discussion
Moving Average without dates
- 8 years ago
HI Anonymous
One approach is to add an Index column and then use that to generate your "last three items" average. I have attached a PBIX file (you can hide the Index col if you like).
The index calculated column can be added like this
Index = RANKX('Table1','Table1'[Date],,ASC)With the moving average column using it in this way
Moving Average = VAR MyIndex = Table1[Index] VAR myResult = AVERAGEX( FILTER( 'Table1', 'Table1'[Index] > MyIndex-3 && 'Table1'[Index] <= MyIndex ),'Table1'[Value] ) RETURN FIXED(myResult,2)
HI Anonymous
One approach is to add an Index column and then use that to generate your "last three items" average. I have attached a PBIX file (you can hide the Index col if you like).
The index calculated column can be added like this
Index = RANKX('Table1','Table1'[Date],,ASC) With the moving average column using it in this way
Moving Average =
VAR MyIndex = Table1[Index]
VAR myResult =
AVERAGEX(
FILTER(
'Table1',
'Table1'[Index] > MyIndex-3 &&
'Table1'[Index] <= MyIndex
),'Table1'[Value]
)
RETURN FIXED(myResult,2) - Anonymous8 years agoNot applicable
Phil, thank you so much!
- Anonymous7 years agoNot applicable
Hello Phil_Seamark once again :)
I am still stuck with the task. I need a average for prices that are collected on a weekly basis, but often the days are omitted, for that I have created an index that reset after change. It has 4 levels - Region, Municipality, Product Category, Product Name - after we move to next municipality with different category and product, index is reset.
When I use your formula on this file, I get huge numbers, I think it is summing everything beneath without taking into consideration index.
Thanks in advance!
Best,
Levan
- Anonymous7 years agoNot applicable
Phil_Seamark you, sir, are a HERO.
I was trying to create moving averages using dates, but every time I filtered the date to show only the last 12 months (and I have 5 years of data, so it needs filtering) the measure would crash. Using an index solved the problem, I would never think of this.
Thanks for sharing.
- mkr6 years agoFrequent Visitor
Hi!
Very useful post but I have another question. How can I calculate moving average without creating calculated columns and using only measures? I'm connected to SQL analysis server and I cannot create calculated columns.
I'd like to calculate average duration of the last 3 Name_IDs. My goal is to plot Name_IDs on x axis and Moving average as value.
Input:
My current attempt:
Moving average = VAR index = RANKX ( ALLSELECTED ( NAME ), CALCULATE(MAX(Table1[EndDate])), , ASC ) Return AVERAGEX( FILTER( Table1, indexName >index-3 && -- indexName is another measure that is equal to VAR index indexName <= index ),Table1[Duration] )Thank you!
- Hassan_BR4 years agoRegular Visitor
Thanks for the suggestion! How do I resolve the same question, using moving standart deviation? I tried to substitute AVERAGEX for STDEVX.P, but the result was not correct.
- Hassan_BR4 years agoRegular Visitor
I believe I've found my mistake. I had to fill the blank values with 0 and use STDEVX.S