If I can make a suggestion (two, actually) to go down another track:
a) this task is much better suited to Power Query than DAX
b) if you can, ditch your standard data table and substitute @Melissa’s awesome Extended Date Table.
The daily, weekly, monthly and yearly offsets in this date table will make this calculation a breeze.
Here’s the link to the date table code:
The date table video:
https://portal.enterprisedna.co/courses/303649/lectures/23833092
And the video on using the offsets:
Should give you everything you need, but if you still have questions just give a shout.
I hope this is helpful.
– Brian