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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.