Announcements
cancel
Showing results for
Did you mean:
Specialist

## Generate 20 weeks in calendar

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 (3)

• ### Script

1 Solution

Accepted Solutions
Partner - Creator

// Define the start and end dates for the calendar
LET vStartDate = Date(YearStart(AddYears(Today(), -1)), 'YYYY-MM-DD');
LET vEndDate = Date(YearEnd(Today()), 'YYYY-MM-DD');

// Create a calendar table with one row for each date
Calendar:
Date(\$(vStartDate) + RowNo() - 1) AS Date
AUTOGENERATE \$(vEndDate) - \$(vStartDate) + 1;

// Add week number and year fields to the calendar table
Left Join (Calendar)
Date,
Week(Date) AS WeekNumber,
Year(Date) AS Year
RESIDENT Calendar;

// Select the last 20 weeks of data
CalendarWeeks:
WeekNumber,
Year
RESIDENT Calendar

// Drop the original calendar table
DROP TABLE Calendar;

Thanks and Regards
Mayur Ingale
2 Replies
Partner - Creator

// Define the start and end dates for the calendar
LET vStartDate = Date(YearStart(AddYears(Today(), -1)), 'YYYY-MM-DD');
LET vEndDate = Date(YearEnd(Today()), 'YYYY-MM-DD');

// Create a calendar table with one row for each date
Calendar:
Date(\$(vStartDate) + RowNo() - 1) AS Date
AUTOGENERATE \$(vEndDate) - \$(vStartDate) + 1;

// Add week number and year fields to the calendar table
Left Join (Calendar)
Date,
Week(Date) AS WeekNumber,
Year(Date) AS Year
RESIDENT Calendar;

// Select the last 20 weeks of data
CalendarWeeks:
WeekNumber,
Year
RESIDENT Calendar