Forum Discussion

dwel0120's avatar
dwel0120
Helper III
5 years ago

Dynamic Week Number

I want to include the last 13 weeks of data in my charts from today's week. I first created a new column for 

Past13Weeks = IF(DATEDIFF([WEEKOF],TODAY(),DAY)<=91, 1, 0) but quickly realized that wouldn't work for year over year data, so now I am moving on to week number. Here are my columns SCHOOLYEAR, WEEKOF, WKNM, ect. 

3 Replies

  • dwel0120 , do you have year and week number too,

     

    Usually, we can create a rank on year week, A new column. But it should be in week/date column

     

    New column Rank

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

     

    new  measures

    Last 13 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-13 && 'Date'[Week Rank]<=max('Date'[Week Rank])))
    This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
    Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))