Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Dynamic Week on Week comparison

Hello,

 

I'd like to know how to make a dynamic WoW comparison. I have 14 days of sales data that is updated daily.

 

So for example, on Monday days 1-7 are aggregated and a variance is shown for the aggregate of days 8-14 (Week 1 vs Week 2). On Tuesdays, the previous day, Monday, is compared to the previous Monday in the dataset. On Wednesdays, the aggregate of the most recent Monday & Tuesday is compared to the aggregate of the Monday & Tuesday in the previous week. This logic follows up to Sunday, where the aggregate of the full week completed is compared to the previous full week.

 

For reference, the sales data has dates and day of the week names.

 

Thanks for any help of guidance in advance,

C

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  Anonymous ,

     

    Here are the steps you can follow:

    1. Create measure.

    Flag =
    var _today=
    TODAY()
    var _week=
    WEEKNUM(_today,2)
    var _weekday=
    WEEKDAY(_today,2)
    return
    SWITCH(
        TRUE(),
    _weekday=1 && MAX('Table'[Week]) in {_week,_week-1},1,
    _weekday<>1 &&
    MAX('Table'[Date]) in
    SELECTCOLUMNS(FILTER(ALL('Table'),OR('Table'[Week]=_week&&'Table'[Weekday] <_weekday,'Table'[Week]=_week-1&&'Table'[Weekday] <_weekday)),"date",'Table'[Date])
    ,1,0)
    Measure =
    SUMX(
        FILTER(ALLSELECTED('Table'),
        'Table'[Week]=MAX('Table'[Week])),[Value])

    2. Place [Flag]in Filters, set is=1, apply filter.

    3. Result:

     

     

    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

  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

    Do not include sensitive information or anything not related to the issue or question.

    If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216

    Please show the expected outcome based on the sample data you provided.

    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

     

    Here are the steps you can follow:

    1. Create measure.

    Flag =
    var _today=
    TODAY()
    var _week=
    WEEKNUM(_today,2)
    var _weekday=
    WEEKDAY(_today,2)
    return
    SWITCH(
        TRUE(),
    _weekday=1 && MAX('Table'[Week]) in {_week,_week-1},1,
    _weekday<>1 &&
    MAX('Table'[Date]) in
    SELECTCOLUMNS(FILTER(ALL('Table'),OR('Table'[Week]=_week&&'Table'[Weekday] <_weekday,'Table'[Week]=_week-1&&'Table'[Weekday] <_weekday)),"date",'Table'[Date])
    ,1,0)
    Measure =
    SUMX(
        FILTER(ALLSELECTED('Table'),
        'Table'[Week]=MAX('Table'[Week])),[Value])

    2. Place [Flag]in Filters, set is=1, apply filter.

    3. Result:

     

     

    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

  • The rolling date boundary approach in the accepted solution works well. One edge case to handle: when today is Monday, WEEKDAY(TODAY(), 2) = 1, so the boundary calculation gives you days 1–7 correctly. But if data arrives with a 1-day lag (common in retail), you need to offset by -1:

     
     
    Current Week Sales =
    VAR _today = TODAY() - 1 -- adjust for data lag
    VAR _dayOfWeek = WEEKDAY(_today, 2)
    VAR _weekStart = _today - _dayOfWeek + 1
    RETURN
    CALCULATE(
    [Sales],
    'Date'[Date] >= _weekStart,
    'Date'[Date] <= _today
    )

    For retail dashboards where store managers need to compare this week vs last week across multiple metrics themselves in the published report, Flexa Tables on AppSource handles WoW as a one-click column  no DAX boundary calculations needed