Announcements
Applications are open for the 2024 Qlik Luminary Program. Apply by December 15 here.
cancel
Showing results for
Did you mean:  Creator III

## Generate 20 weeks in calendar

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_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);

Labels (1)
• ### General Question

2 Replies  Master

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));

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  MVP

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_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); Tags
Community Browser