Forum Discussion

newlearnpbi123's avatar
2 years ago
Solved

How to calculate rolling 5 week average ?

I have only date column which contains weeks, now i want to calculate rolling 5 week average, i tried dateinperiod could not get it to work. thank you   PaulDBrown 
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Sergii24 ,thanks for the quick reply, I'll add further.

    Hi newlearnpbi123 ,

    The Table data is shown below:

    Please follow these steps:
    1. Use the following DAX expression to create a column

    Weeknumber = WEEKNUM([Date],2)

    2. Use the following DAX expression to create a measure

    Measure = 
    VAR _a = SELECTEDVALUE('Table'[Weeknumber])
    VAR _b = CALCULATE(AVERAGE('Table'[Unit]),FILTER(ALL('Table'),'Table'[Weeknumber] <= _a && 'Table'[Weeknumber] >= _a -4 ))
    RETURN _b

    3.Final output