Forum Discussion

Rachitik67's avatar
Rachitik67
Frequent Visitor
2 years ago
Solved

Variation week over week with a baseline

Hi, 

i am trying to calculation the variation between weeks. However, i want the current week to be the baseline.

 

For example : 

Variation current week vs week 16 = current week - week 16 / week 16 = 46983 - 44469 / 44469

Variation current week vs week 5 = current week - week 24 / week 24 = 46983 - 46937 / 46937

 

The current week always has the highest week number.

 

Here is a sample of my table in PBI :

 

 

Thank you

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  Rachitik67 ,

     

    Here are the steps you can follow:

     

    You can use the following dax.

    Calculated column:

    Column =
    var _currentweek=
    MAXX(ALL('Table'),'Table'[No de Semaine])
    var _currentvalue=
    SUMX(
        FILTER(ALL('Table'),'Table'[No de Semaine]=_currentweek),[Inscr_this_week])
    return
    DIVIDE(
    _currentvalue - 'Table'[Inscr_this_week],'Table'[Inscr_this_week])

    Measure:

    Measure =
    var _currentweek=
    MAXX(ALL('Table'),'Table'[No de Semaine])
    var _currentvalue=
    SUMX(
        FILTER(ALL('Table'),'Table'[No de Semaine]=_currentweek),[Inscr_this_week])
    return
    DIVIDE(
    _currentvalue - MAX('Table'[Inscr_this_week]),MAX('Table'[Inscr_this_week]))

     

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

3 Replies

  • Rachitik67 ,

     

    Have these new columns in Date Table, Week Rank is Important in Date/Week Table

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


    These measures can help
    This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
    Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

     

    Max week

     

    Have these new columns in Date Table, Week Rank is Important in Date/Week Table

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


    These measures can help
    Max Week =

    Var _max  = Maxx(allselected('Date'), 'Date'[Week Rank])

    return

    CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=_max  ))

     

    Power BI — Week on Week and WTD
    https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
    https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
    https://www.youtube.com/watch?v=pnAesWxYgJ8
    Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510

    • Rachitik67's avatar
      Rachitik67
      Frequent Visitor

      I am sorry, but i don't see any variation calculation with the current week baseline.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Rachitik67 ,

     

    Here are the steps you can follow:

     

    You can use the following dax.

    Calculated column:

    Column =
    var _currentweek=
    MAXX(ALL('Table'),'Table'[No de Semaine])
    var _currentvalue=
    SUMX(
        FILTER(ALL('Table'),'Table'[No de Semaine]=_currentweek),[Inscr_this_week])
    return
    DIVIDE(
    _currentvalue - 'Table'[Inscr_this_week],'Table'[Inscr_this_week])

    Measure:

    Measure =
    var _currentweek=
    MAXX(ALL('Table'),'Table'[No de Semaine])
    var _currentvalue=
    SUMX(
        FILTER(ALL('Table'),'Table'[No de Semaine]=_currentweek),[Inscr_this_week])
    return
    DIVIDE(
    _currentvalue - MAX('Table'[Inscr_this_week]),MAX('Table'[Inscr_this_week]))

     

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly