Forum Discussion
Make DAX code dynamic instead of hard-coded
It's very easy in fact. You just have to number all your weeks consecutively 1, 2, 3... and use this number instead of the form YYYYMM. Also, you should number the weeks belonging to the same year 1, 2, 3,..., 52/53 for each year. Then the IF will sense if you're in the last week of the year (even better: instead of the latter numbering create an indicator column that will tell you if you're on the last week of the year) and all you'll have to do is to advance the first consecutive number by 1 if you find you're on the last week of the year. That's fully dynamic.
If all the years have the same number of weeks in them, say 53, you can also use the clock arithmetic to simplify the formulas. You wouldn't need any IF for this to work if you do your calculations modulo 53.