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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Calculate WTD sales for same week last year, but for the same number of elapsed days

Hi!

 

Im struggeling with a time int. measure to calculate total sales last year. The main goal is to be able to show a table with [Department], [#Sales WTD] and [#Sales WTD_LY)] - without the need of any slicers at all, where the measure it self takes into account the current weeknumber based on NOW() / TODAY(). 

 

This is working fine with some easy measures, but my main problem is that [#Sales WTD_LY] calculates the sum for the whole week last year, and not for instance: only sales from monday until thursday (todays day). This makes it quite useless a KPI.

 

So - does anyone know how to take this into account?

 

Thanks! (Mock data set = https://ufile.io/uarzc)

 

(My week starts on Mondays FYI Smiley Happy)

 

#SalesTotal = SUM([NetAmount])
#SalesTotal_LY = CALCULATE([#SalesTotal];DATEADD(Dates[Date];-1;YEAR))

#SalesWTD = 
CALCULATE([#SalesTotal];
    FILTER(
        Dates;
            YEAR( Dates[Date] ) = YEAR( NOW() )
                && WEEKNUM( Dates[Date];2 ) = WEEKNUM( NOW();2)
    )
)
#SalesWTD_LY = 
CALCULATE([#SalesTotal_LY];
    FILTER(
        Dates;
            YEAR( Dates[Date] ) = YEAR( NOW() )
                && WEEKNUM( (Dates[Date]);2 ) = WEEKNUM( NOW();2)
    )
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous,


Create the following columns in your Dates table.

WeekNumber = WEEKNUM(Dates[Date],2)
Year = YEAR(Dates[Date])


Then create the following measure in your sales table.

SameWeekLastYear = IF (
    HASONEVALUE ( 'Dates'[Year] )
        && HASONEVALUE ('Dates'[WeekNumber] ), CALCULATE(
        sales[#SalesTotal],
        FILTER (
            ALL ( 'Dates' ),
            'Dates'[Year] = VALUES ( 'Dates'[Year] )-1
                && 'Dates'[WeekNumber] = VALUES ( 'Dates'[WeekNumber] )
                && 'Dates'[WeekNumber] = WEEKNUM(NOW(),2 )
        )
    ))

1.PNG

Reference:
http://www.dutchdatadude.com/ultimate-time-based-calculations-cheat-sheet-for-dax-power-bi-including-week-based-calculations/

Regards,
Lydia

View solution in original post

1 REPLY 1
Anonymous
Not applicable

@Anonymous,


Create the following columns in your Dates table.

WeekNumber = WEEKNUM(Dates[Date],2)
Year = YEAR(Dates[Date])


Then create the following measure in your sales table.

SameWeekLastYear = IF (
    HASONEVALUE ( 'Dates'[Year] )
        && HASONEVALUE ('Dates'[WeekNumber] ), CALCULATE(
        sales[#SalesTotal],
        FILTER (
            ALL ( 'Dates' ),
            'Dates'[Year] = VALUES ( 'Dates'[Year] )-1
                && 'Dates'[WeekNumber] = VALUES ( 'Dates'[WeekNumber] )
                && 'Dates'[WeekNumber] = WEEKNUM(NOW(),2 )
        )
    ))

1.PNG

Reference:
http://www.dutchdatadude.com/ultimate-time-based-calculations-cheat-sheet-for-dax-power-bi-including-week-based-calculations/

Regards,
Lydia

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (8,898)