Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
1b0r90
Frequent Visitor

SUM of MAX date from last week

I have a dataset which is upated 3 times a week, by appending the new data at the end of the dataset. I need to display the movement of the values in a table comparing the SUM of values from latest day this week and last week.

 

The data looks like this:

CustomerReport DateValue
A13/05/20205
B13/05/202010
A11/05/20202
B11/05/202012
A08/05/20203
B08/05/202015
A06/05/20204
B06/05/202014

 

I need to create a measure that will give me the SUM of MAX(Report Date) for most recent week and for most recent week -1.

 

This is what I come up with so far, but it sums up the whole last week of data. I created a calculated column (WeekNum), which I would also like to avoid if possible.

Last Week =
VAR CurrentWeek = MAX('Main table'[WeekNum])

RETURN
CALCULATE(
SUM('Main table'[Value]),
FILTER('Main table', 'Main table'[WeekNum]=CurrentWeek-1))
1 ACCEPTED SOLUTION
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please take following steps:

1)Create this column:

WeekNo = WEEKNUM('Table'[Report Date])

2)Try these two measures:

Current_Week = 
VAR a =
    CALCULATE (
        MAX ( 'Table'[Report Date] ),
        FILTER ( 'Table', 'Table'[WeekNo] = WEEKNUM ( TODAY () ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[WeekNo] = WEEKNUM ( TODAY () )
                && 'Table'[Report Date] = a
        )
    )
Last_Week = 
VAR a =
    CALCULATE (
        MAX ( 'Table'[Report Date] ),
        FILTER ( 'Table', 'Table'[WeekNo] = WEEKNUM ( TODAY () ) - 1 )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[WeekNo]
                = WEEKNUM ( TODAY () ) - 1
                && 'Table'[Report Date] = a
        )
    )

3)The result shows:

12.PNG

See my attached pbix file.

 

Best Regards,

Giotto

View solution in original post

3 REPLIES 3
1b0r90
Frequent Visitor

@amitchandak Your solution gave me an error, but it helped me to end up something very similar to what @v-gizhi-msft suggested, so I will mark that one as the solution.

Thank you both for your inputs!

v-gizhi-msft
Community Support
Community Support

Hi,

 

Please take following steps:

1)Create this column:

WeekNo = WEEKNUM('Table'[Report Date])

2)Try these two measures:

Current_Week = 
VAR a =
    CALCULATE (
        MAX ( 'Table'[Report Date] ),
        FILTER ( 'Table', 'Table'[WeekNo] = WEEKNUM ( TODAY () ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[WeekNo] = WEEKNUM ( TODAY () )
                && 'Table'[Report Date] = a
        )
    )
Last_Week = 
VAR a =
    CALCULATE (
        MAX ( 'Table'[Report Date] ),
        FILTER ( 'Table', 'Table'[WeekNo] = WEEKNUM ( TODAY () ) - 1 )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[WeekNo]
                = WEEKNUM ( TODAY () ) - 1
                && 'Table'[Report Date] = a
        )
    )

3)The result shows:

12.PNG

See my attached pbix file.

 

Best Regards,

Giotto

amitchandak
Super User
Super User

Try like

 

This Week Measure =
VAR __Week = MAX('Table'[WeekNum])
VAR __id = MAX ( 'Table'[Customer] )
VAR __date = CALCULATE ( MAX( 'Table'[date] ), ALLSELECTED ( 'Table' ), 'Table'[Customer] = __id )
RETURN CALCULATE ( Sum ( 'Table'[Value] ), VALUES ( 'Table'[Customer ), 'Table'[Customer] = __id, 'Table'[date] = __date,'Table'[WeekNum] =__Week )

 

 

Last week Measure =
VAR __Week = MAX('Table'[WeekNum])-1
VAR __id = MAX ( 'Table'[Customer] )
VAR __date = CALCULATE ( MAX( 'Table'[date] ), ALLSELECTED ( 'Table' ), 'Table'[Customer] = __id )
RETURN CALCULATE ( Sum ( 'Table'[Value] ), VALUES ( 'Table'[Customer ), 'Table'[Customer] = __id, 'Table'[date] = __date,'Table'[WeekNum] =__Week )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.