Forum Discussion

monojchakrab's avatar
monojchakrab
Icon for Resolver III rankResolver III
4 years ago
Solved

week on week comparison

Hiya All,

 

I am trying to do a same week last month and previous week same month comparison.

 

Is there any function to do that or a guide to a measure which can help me do that?

 

I have a data table (attached), which has the weeknumber for every month with the date ranges (e.g. 1-7th is week 1, 8th-14th is week 2 and so on).

 

DateYEARMONTH NAMEMONTH NUMBERDAY NAMEWEEK NO
27-02-20222022Feb2Sun4
28-02-20222022Feb2Mon4
01-03-20222022Mar3Tue1
02-03-20222022Mar3Wed1
03-03-20222022Mar3Thu1
04-03-20222022Mar3Fri1
05-03-20222022Mar3Sat1
06-03-20222022Mar3Sun1
07-03-20222022Mar3Mon1
08-03-20222022Mar3Tue2
09-03-20222022Mar3Wed2
10-03-20222022Mar3Thu2
11-03-20222022Mar3Fri2
12-03-20222022Mar3Sat2
13-03-20222022Mar3Sun2
14-03-20222022Mar3Mon2
15-03-20222022Mar3Tue3
16-03-20222022Mar3Wed3
17-03-20222022Mar3Thu3
18-03-20222022Mar3Fri3
19-03-20222022Mar3Sat3
20-03-20222022Mar3Sun3
21-03-20222022Mar3Mon3
22-03-20222022Mar3Tue4

 

Thanks

  • monojchakrab , Create week or month columns

     

    min week start of month = minx(filter('Date',[Month Year] =earlier([Month Year])),[Week Start date])


    week of month = datediff([min week start of month],[date],Week)+1
    or
    week of month = quotient(datediff([min week start of month],[date],day),7)+1

     

    or

    Start Month = eomonth([date],-1)+1

     

    Month Week Start = [Start Month ] + QUOTIENT(datediff([Start Month],[date],day),7) *7

     

    Create month rank

    Month Rank = RANKX(all('Date'),'Date'[Month Start],,ASC,Dense)

     

    MWTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank]) && [week of month] <=max([week of month])))
    LMETD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])-1 && [week of month] <=max([week of month])))

     

     

    refer

    Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
    Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

5 Replies

  • monojchakrab , Create week or month columns

     

    min week start of month = minx(filter('Date',[Month Year] =earlier([Month Year])),[Week Start date])


    week of month = datediff([min week start of month],[date],Week)+1
    or
    week of month = quotient(datediff([min week start of month],[date],day),7)+1

     

    or

    Start Month = eomonth([date],-1)+1

     

    Month Week Start = [Start Month ] + QUOTIENT(datediff([Start Month],[date],day),7) *7

     

    Create month rank

    Month Rank = RANKX(all('Date'),'Date'[Month Start],,ASC,Dense)

     

    MWTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank]) && [week of month] <=max([week of month])))
    LMETD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])-1 && [week of month] <=max([week of month])))

     

     

    refer

    Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
    Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

  • amitchandak , Amit, this is partly solving the problem...

     

    What I am looking to solve is as follows :

     

    If I have the table like this :

     

    Apr : wk1...wk4//May : wk1...wk4

     

    So I want to compare two columns of data as follows :

     

    1. May : wk4/wk3;wk3/wk2;wk2/wk1 &

    2. Sales for same week last month :

    May wk1/Apr wk1//May wk2/Apr wk2//May wk3/Apr wk3//May wk4/Apr wk4

     

    That does not seem to be possible with this code...

     

    Note : I have added the columns in the date table as required as per this code