Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Trailing 12 Week Average

Hi everyone, 

 

I have just started using Power BI and DAX however I have been struggling with a trailing average measure. My data is sorted like the example data below.

 

The problem I am having is that all functions seem to aim at dates instead of week numbers.

What formula could create a trailing average for 12 weeks excluding the current week? 

 

Currently I am using something like this 

 

Measure = 
  VAR __CurrentWeek = WEEKNUM(TODAY())
  VAR __StartWeek = __CurrentWeek - 13
RETURN
  AVERAGEX(FILTER('Table', [Week No] >= __StartWeek && [Week No] < __CurrentWeek),[Salesvalue])

 

However, this takes an average of the individual vales for sales value. I need the averages for the sum of the entire week. 

Hope someone can help me.

 

Kind regards, 

Majesteit 

Week NoSalesvalueParameter 1 Parameter 2 

1

345PromoStore
134RegularOnline
221 PromoStore
21245RegularOnline
35636PromoStore
337RegularOnline
435PromoStore
  • Anonymous , I would Advice to use week Rank, inplace of week num,

     

    Try a meausre like

    Avg Last 13 weeks = CALCULATE(Averagex(Values('Date'[Week Rank]), [Sales Value]) , FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-13 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

     

     

    Where Week Rank is column

     

    Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
    OR
    Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

1 Reply

  • Anonymous , I would Advice to use week Rank, inplace of week num,

     

    Try a meausre like

    Avg Last 13 weeks = CALCULATE(Averagex(Values('Date'[Week Rank]), [Sales Value]) , FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-13 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

     

     

    Where Week Rank is column

     

    Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
    OR
    Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format