Generiert einen Masterkalender für ein Datumsfeld.

Bitte beachten Sie das Sie ein Datumsfeld nutzen welches im Qlik Format vorliegt und keine Stunden / Minuten / Sekunden enthält.

Im Developer Cookbook finden Sie weitere Informationen zu Datum und Zeit.

Der Masterkalender kann mehrfach eingebunden werden, bitte beachten Sie das für weitere Einbindungen entweder die Variable calPreFix oder calSubFix und CalendarName gesetzt sein muss.

Warum sollte man mehrere Kalender benutzen erklärt Henric Cronström auch in seinem Design Blog.

Die alternative wäre eine sogenannte Link Table. Diese nutze ich persönlich nur sehr ungerne weil dadurch die Transparenz an der Oberfläche leidet, siehe Beitrag Henric Cronström.

Beispiel für die Nutzung:

set  DateTableName 	= 'Facts';
// Name of Date Field		
set DateFieldName 	= '%OrderDate';
set createFiscal 	= 'true';			
set FiscalShift 	= 7;
$(Must_Include=$(incPath)MasterCalendarV2.qvs);

Beispiel für die Nutzung mit 2 Datumsfeldern:

/ Loading MasterCalendar
set DateTableName 	= 'Facts';
// Name of Date Field		
set DateFieldName 	= '%OrderDate';
set CalendarName 	= 'OrderCalendar';
set calSubfix 		= ''; 
set createFiscal 	= 'true';			
set FiscalShift 	= 7;
$(Must_Include=$(incPath)MasterCalendarV2.qvs);

// OnTop add Shipment Calendar
set DateTableName 	= 'Facts';
// Name of Date Field		
set DateFieldName 	= '%ShipmentDate';
set CalendarName 	= 'ShipmentCalendar';
set calSubfix 		= '.Shipment'; 
set createFiscal 	= 'true';			
set FiscalShift 	= 7;
$(Must_Include=$(incPath)MasterCalendarV2.qvs);

Gesamtes Script welches über den obigen Include Befehl eingebunden wird:

/****************************************************************
* 	@Project:	MasterCalendar
*
*	@Author:	Thomas Lindackers
*	@Version:	2.2
*
*	@last changes: 30.08.2017
*
*****************************************************************/
Trace Building MasterCalendar @ $(ProjectName);
Trace ----------------------------------------------------------;

For i = 1 To 10
Trace $(i);
Next i;

	/*
		Getting Min an MaxDate and store to DB
	*/

	IF FiscalShift = '' or isNull(FiscalShift)  THEN
		FiscalShift = 0;

	ENDIF

	IF CalendarName = '' or isNull(CalendarName) THEN
		set CalendarName = 'MasterCalendar';
	endIf

	$(CalendarName):
	LOAD
		*,
		$(calPrefix)Year$(calSubfix) & '-' & $(calPrefix)Quarter$(calSubfix) as $(calPrefix)YearQtr$(calSubfix)
		// Create Fiscal Values this will be removed in case of createFiscal = false
		, $(calPrefix)FiscalQuarter$(calSubfix) & '-' & $(calPrefix)FiscalYear$(calSubfix) as $(calPrefix)FiscalQtrYear$(calSubfix)
		, $(calPrefix)Month$(calSubfix) & '-' & $(calPrefix)FiscalYear$(calSubfix) as FiscalMonthYear$(calSubfix)
	;
	LOAD
		TempDate AS $(DateFieldName)

		, Year(TempDate) AS $(calPrefix)Year$(calSubfix)
		, Month(TempDate) AS $(calPrefix)Month$(calSubfix)
		, Day(TempDate) AS $(calPrefix)Day$(calSubfix)

		, Week(TempDate) AS $(calPrefix)Week$(calSubfix)
		, Weekday(TempDate) AS $(calPrefix)WeekDay$(calSubfix)

		, 'Q' & ceil(month(TempDate) / 3) AS $(calPrefix)Quarter$(calSubfix)

		, Date(monthstart(TempDate), 'MMM-YYYY') AS $(calPrefix)MonthYear$(calSubfix)
		, Year(TempDate) &'-'& Week(TempDate) AS $(calPrefix)YearWeek$(calSubfix)

		// Create Fiscal Values this will be removed in case of createFiscal = false
		, Year(YearStart ( TempDate, 0 ,$(FiscalShift))) As $(calPrefix)FiscalYear$(calSubfix)
		, 'Q' & Ceil( Month(MonthStart ( TempDate, -$(FiscalShift))) / 3) as $(calPrefix)FiscalQuarter$(calSubfix)
	;

	LOAD
	 date(mindate + IterNo()) AS TempDate
	 ,maxdate // Used in InYearToDate() above, but not kept
	WHILE mindate + IterNo() <= maxdate;

	LOAD
		min(FieldValue('$(DateFieldName)', recno()))-1 as mindate,
		max(FieldValue('$(DateFieldName)', recno())) as maxdate
	AUTOGENERATE FieldValueCount('$(DateFieldName)');

	IF createFiscal = 'false' OR isNull(createFiscal) THEN
		Drop Fields
			  $(calPrefix)FiscalYear$(calSubfix)
			, $(calPrefix)FiscalQuarter$(calSubfix)
			, $(calPrefix)FiscalQtrYear$(calSubfix)
			, $(calPrefix)FiscalMonthYear$(calSubfix)
		;
	ENDIF

	IF dropRealFields = 'true' and not isNull(dropRealFields) THEN
		Drop Fields
			  $(calPrefix)Year$(calSubfix)
			, $(calPrefix)YearWeek$(calSubfix)
			, $(calPrefix)MonthYear$(calSubfix)
		;
	ENDIF