Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello
I'm trying to generate a calendar but I want this calendar to only generate 20 weeks for me instead of 104 weeks.
What's the best way to do it? This is the variable v_date_end_calendrier :
LET v_date_start_calendar = YearStart(AddYears(today(), -1));
LET v_date_end_calendrier =YearEnd(today());
LET v_nb_week_calendar = round((v_date_end_calendrier - v_date_start_calendar) / 7);
LET v_date_start_calendar_week = WeekStart(Today() - 7 * (v_nb_week_calendar-1));
LET v_nb_month_calendrier = Num(((year(Today())*12)+month(Today()))-((year(v_date_start_calendar)*12)+month(v_date_start_calendar))+1);
LET v_date_start_calendrier_mois = MonthStart(Today(), - v_nb_month_calendrier + 1);
you can use the iterno() function to generate numbers and from there play around with the dates. its hard to understand your variables but whats really needed is a reference point like when does your calendar end or start. this example works backwards starting from the current full week (today being 4/26, it ends at the end of the week 4/29) and goes back 4 weeks:
load
date(WeekEnd(today())-iterno()+1) as date
while
date(WeekEnd(today())-iterno()+1) <= WeekEnd(today())
and date(WeekEnd(today())-iterno()+1)>date(WeekEnd(today())-(7*4));
load 1 AutoGenerate(1);
the number of weeks is specified in the last phrase of the where clause 7*4 so substitute that with 7*20
the idea is iterrate through numbers from 1 to n while the calculated date is between the end of this week and back the end of this week - 7 days * number of weeks
You can modify the calculation of v_nb_week_calendar to limit the number of weeks to 20 instead of the total number of weeks between the start and end dates.
Here's an updated script that sets v_nb_week_calendar to 20 weeks
LET v_date_start_calendar = YearStart(AddYears(today(), -1));
LET v_date_end_calendrier =YearEnd(today());
LET v_nb_week_calendar = 20; // Set the number of weeks to 20
LET v_date_start_calendar_week = WeekStart(Today() - 7 * (v_nb_week_calendar-1));
LET v_nb_month_calendrier = Num(((year(Today())*12)+month(Today()))-((year(v_date_start_calendar)*12)+month(v_date_start_calendar))+1);
LET v_date_start_calendrier_mois = MonthStart(Today(), - v_nb_month_calendrier + 1);