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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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:
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.
My Dax is not working as expected.
Solved! Go to Solution.
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
it worked. Thank you!!!
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
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 39 | |
| 37 | |
| 29 | |
| 24 |
| User | Count |
|---|---|
| 120 | |
| 95 | |
| 70 | |
| 69 | |
| 65 |