Forum Discussion
Moving average based on prior N rows
- 6 years ago
The comma goes before the All(). Try doing just All('Normalized Calendar') instead (remove the column reference).
Regards,
Pat
- 6 years ago
StephaneMA colum type is whole number/decimal. Can you copy the table which i shared above and create the same measure (not calculated column) without any edits. Also share the snapshot.?
Try this DAX measure.
Moving Avg =
VAR n = 5
VAR current =
SELECTEDVALUE ( Table[weeknumber] )
VAR avg =
CALCULATE (
AVERAGE ( Table[Subs] ),
FILTER (
ALL ( Table[weeknumber] ),
Table[weeknumber] <= current
&& Table[weeknumber] >= current - n
)
)
RETURN
avg
Did I answer your question? Mark my post as a solution!
Appreciate with a kudos 🙂
Thank you nandukrishnavs,
I appreciate the suggestion. I get exactly the same result than I did with Pat's suggestion above.
- nandukrishnavs6 years ago
Community Champion
Weeknumber Subs 1 282 2 508 3 540 4 518 5 717 6 599 7 622 8 416 9 603 10 622 11 730 12 617 13 618 Moving Avg = VAR n = 5 VAR _selectedweekno = SELECTEDVALUE ( 'Table'[Weeknumber] ) VAR result = CALCULATE ( AVERAGE ( 'Table'[Subs] ), FILTER ( ALL ( 'Table'[Weeknumber] ), 'Table'[Weeknumber] <= _selectedweekno && 'Table'[Weeknumber] >= _selectedweekno - n ) ) RETURN IF(_selectedweekno>=n,result,BLANK())
Did I answer your question? Mark my post as a solution!
Appreciate with a kudos 🙂- StephaneMA6 years agoFrequent Visitor
I appreciate the help but I do not get the same result at all. I created a new table with the same data to replicate your formula but I get bery different results....
I am not sure at this point what I am doing wrong to get this result.
- nandukrishnavs6 years ago
Community Champion
StephaneMA colum type is whole number/decimal. Can you copy the table which i shared above and create the same measure (not calculated column) without any edits. Also share the snapshot.?