Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

this week versus last week difference

I have a table below in which i wanted to calculate or get the difference from this week's count against last week. below is a sample table output that i wanted to achieve. i wanted to get a dax formula for the Week Difference. Thank you in advance.

 

CountOfECMsWEEKENDINGSATWeek Difference
2112/2/2017 
3012/9/20179
3312/16/20173
1112/23/2017-22
812/30/2017-3
111/6/20183
251/13/201814
321/20/20187
161/27/2018-16
172/3/20181
252/10/20188
202/17/2018-5
222/24/20182
193/3/2018-3
173/10/2018-2
  • Hi, Anonymous 

    Please try formula like:

    Week Difference = 
    VAR last_week =
        CALCULATE (
            MAX ( 'Table'[WEEKENDINGSAT] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[WEEKENDINGSAT] < MAX ( 'Table'[WEEKENDINGSAT] )
            )
        )
    VAR _count_of_lastweek =
        CALCULATE (
            [CountOfECMs1],
            FILTER ( ALL ( 'Table' ), 'Table'[WEEKENDINGSAT] = last_week )
        )
    RETURN
        IF (
            ISBLANK ( _count_of_lastweek ),
            BLANK (),
            [CountOfECMs1] - _count_of_lastweek
        )

    Best Regards,
    Community Support Team _ Eason

2 Replies

  • v-easonf-msft's avatar
    v-easonf-msft
    Community Support

    Hi, Anonymous 

    Please try formula like:

    Week Difference = 
    VAR last_week =
        CALCULATE (
            MAX ( 'Table'[WEEKENDINGSAT] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[WEEKENDINGSAT] < MAX ( 'Table'[WEEKENDINGSAT] )
            )
        )
    VAR _count_of_lastweek =
        CALCULATE (
            [CountOfECMs1],
            FILTER ( ALL ( 'Table' ), 'Table'[WEEKENDINGSAT] = last_week )
        )
    RETURN
        IF (
            ISBLANK ( _count_of_lastweek ),
            BLANK (),
            [CountOfECMs1] - _count_of_lastweek
        )

    Best Regards,
    Community Support Team _ Eason