Forum Discussion

drx's avatar
drx
Frequent Visitor
1 year ago
Solved

Cumulative Comparison Between This Week and Last Week in a Single Visual

Hi Power BI Community, I'm working on a report in Power BI where I want to show the cumulative totals for this week and the previous week on the same visual. I'm using DirectQuery mode(so I can't ma...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi,

    Thanks for the solution amitchandak offered, and i want to offer some more information for user to refer to.

    hello drx , based on your description, you can refer to the following sample.

    Sample data 

    Calendar table.

    There is a 1:n relationship between the tables.

    Then for this week  cumulative totals.

    CE Orders =
    IF (
        SUM ( 'T_Verkooporder'[Aantal ce besteld] ) <> BLANK (),
        CALCULATE (
            SUM ( 'T_Verkooporder'[Aantal ce besteld] ),
            ALLSELECTED ( 'DM_Leverdatum' ),
            'DM_Leverdatum'[Datum] <= MAX ( 'DM_Leverdatum'[Datum] )
        )
    )
    

    For last week.

    CE Last week = CALCULATE([CE Orders],DATEADD('DM_Leverdatum'[Datum],-7,day))

    Then create a measure to control the last week start from Monday.

    Flag =
    VAR a =
        MAXX ( ALLSELECTED ( 'DM_Leverdatum'[Datum] ), [Datum] )
    VAR b =
        a - WEEKDAY ( a, 2 ) + 1
    RETURN
        IF (
            SELECTEDVALUE ( 'DM_Leverdatum'[Datum] ) >= b
                && SELECTEDVALUE ( 'DM_Leverdatum'[Datum] ) <= a,
            1,
            0
        )
    

    Then put the following fields in visual.

    Then put the falg measure to the visual filter.

     

    Output

     

     

    Best Regards!

    Yolo Zhu

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