Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@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

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.