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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
BlueDaisy
Frequent Visitor

Start Date of the same week number previous year

Hello,

Could you please help me in writting a DAX measure for the calculation of the difference (days) between the start of the this week and the start of the same week NUMBER previous year)? I have a weekly calendar table as shown:

BlueDaisy_0-1689603294648.png

 

I cannot use SAMEPERIODLASTYEAR because the week does not start on the same day. With the small modification of the formula, I get what I need, but 1 day of adjustmet is hardcoded (i am trying to make it dynamic). Thanks.

BlueDaisy_2-1689603638797.png

 

 

My Dax is not working as expected.

BlueDaisy_1-1689603420900.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BlueDaisy ,

Please update the formula of your measure [TestTest] as below and check if it can return your expected result.

TestTest =
VAR _curdate =
    SELECTEDVALUE ( dim_week[WeekStart] )
VAR _year =
    YEAR ( _curdate )
VAR _week =
    WEEKNUM ( _curdate, 2 )
VAR _pywsday =
    CALCULATE (
        MIN ( dim_week[WeekStart] ),
        FILTER (
            ALL ( dim_week ),
            dim_week[WeekStart]
                >= DATE ( _year - 1, 1, 1 )
                && dim_week[WeekStart]
                    <= DATE ( _year - 1, 12, 31 )
                && WEEKNUM ( dim_week[WeekStart], 2 ) = _week
        )
    )
RETURN
    DATEDIFF ( _pywsday, _curdate, DAY )

If the above one can't help you, please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

View solution in original post

2 REPLIES 2
BlueDaisy
Frequent Visitor

it worked. Thank you!!!

Anonymous
Not applicable

Hi @BlueDaisy ,

Please update the formula of your measure [TestTest] as below and check if it can return your expected result.

TestTest =
VAR _curdate =
    SELECTEDVALUE ( dim_week[WeekStart] )
VAR _year =
    YEAR ( _curdate )
VAR _week =
    WEEKNUM ( _curdate, 2 )
VAR _pywsday =
    CALCULATE (
        MIN ( dim_week[WeekStart] ),
        FILTER (
            ALL ( dim_week ),
            dim_week[WeekStart]
                >= DATE ( _year - 1, 1, 1 )
                && dim_week[WeekStart]
                    <= DATE ( _year - 1, 12, 31 )
                && WEEKNUM ( dim_week[WeekStart], 2 ) = _week
        )
    )
RETURN
    DATEDIFF ( _pywsday, _curdate, DAY )

If the above one can't help you, please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.