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

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

Reply
Anonymous
Not applicable

DAX Custom Week Calculations

VAR CurrentWeek = SELECTEDVALUE( Dates[Week_Number] ) VAR CurrentYear = SELECTEDVALUE( Dates[Year] ) VAR MaxWeekNumber = CALCULATE( MAX ( Dates[Week_Number] ), ALL( Dates )) RETURN SUMX( FILTER( ALL( Dates ), IF( CurrentWeek = 1, Dates[Week_Number] = MaxWeekNumber && Dates[Year] = CurrentYear - 1, Dates[Week_Number] = CurrentWeek -1 && Dates[Year] = CurrentYear )), [Total Sales Value] )

 

Hi All, 

 

I found the above code to calculate Total Sales for the Previous Week

I want to amend this to calculate Total Sales for the current week last year

 

Can't figure this out, any ideas!

My data is at a week granularity with a field for week and field for year, no date field exists

 

Thanks in advance

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous,

 

You may try this Measure.

Current Week Of last Year =
VAR CurrentWeek =
    SELECTEDVALUE ( Dates[Week_Number] )
VAR CurrentYear =
    SELECTEDVALUE ( Dates[Year] )
VAR PrevYear = CurrentYear - 1
RETURN
    SUMX (
        FILTER (
            ALL ( Dates ),
            Dates[Year] = PrevYear
                && Dates[Week_Number] = CurrentWeek
        ),
        [Total Sales Value]
)

 

The result looks like this.

vcazhengmsft_0-1655345869145.png

 

vcazhengmsft_1-1655345869146.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you!

v-cazheng-msft
Community Support
Community Support

Hi @Anonymous,

 

You may try this Measure.

Current Week Of last Year =
VAR CurrentWeek =
    SELECTEDVALUE ( Dates[Week_Number] )
VAR CurrentYear =
    SELECTEDVALUE ( Dates[Year] )
VAR PrevYear = CurrentYear - 1
RETURN
    SUMX (
        FILTER (
            ALL ( Dates ),
            Dates[Year] = PrevYear
                && Dates[Week_Number] = CurrentWeek
        ),
        [Total Sales Value]
)

 

The result looks like this.

vcazhengmsft_0-1655345869145.png

 

vcazhengmsft_1-1655345869146.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.