Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
anwarbham
Contributor III
Contributor III

CTD or Cycle to Date calender examples

Hi does anyone have an example or a calender with CTD or cycle to date 

example if you have 

Cycle one Jan>Feb>Mar>Apr

Cycle two May>Jun>Jul>Aug

Cycle three Sep>Oct> Nov>Dec

 

i was thinking sometning in the lines of the below unless someone has a better idea 

FOR i = 0 to 0
		
			$(vTable)_tmp_CTD:
			LOAD
				*,
				Dual(Quarter & '-' & Year, Date(QuarterStart(Addmonths(Date, $(i))), 'MMM-YY')) as [Year Quarter]
			;
			LOAD Distinct
				%Calendar_Key,
				Addmonths(%Calendar_Key, $(i)) 															as Date, 
				Num(Addmonths(%Calendar_Key, $(i))) 													as [Date Num],
				Dual(Month(Addmonths(%Calendar_Key, $(i))), Num(Month(Addmonths(%Calendar_Key, $(i))))) as Month,
				Dual('Q' & Ceil(Month(Addmonths(%Calendar_Key, $(i)))/3), Ceil(Month(Addmonths(%Calendar_Key, $(i)))/3)) AS Quarter,
				Dual('C' & Ceil(Month(Addmonths(%Calendar_Key, $(i)))/4), Ceil(Month(Addmonths(%Calendar_Key, $(i)))/3)) AS Cycle,
				Year(Addmonths(%Calendar_Key, $(i))) 													as Year,
				Date(MonthStart(Addmonths(%Calendar_Key, $(i))), 'MMM-YY') 								as [Year Month],
				Num(MonthStart(Addmonths(%Calendar_Key, $(i)))) 										as [Year Month Num],
				Dual('CTD',1) 	as Timeframe,
				'Cycle-To-Date' 		as [Timeframe Displayed],
				1 				as CTD_CY_TMP
			Resident
				$(vTable)_tmp
			Where
				Num(Addmonths(%Calendar_Key, $(i))) <= $(vMaxDate)
				and Num(AddMonths(%Calendar_Key, $(i))) >= $(vMinDate) 
			;

		NEXT
		
		Concatenate ($(vTable))
		LOAD
			*
		Resident
			$(vTable)_tmp_CTD
		;

 

 

Labels (3)
1 Solution

Accepted Solutions
anwarbham
Contributor III
Contributor III
Author

I managed to get it working 

using the below 

Dual('C' & Ceil(Month(Addmonths(%Calendar_Key, $(i)))/4), Ceil(Month(Addmonths(%Calendar_Key, $(i)))/4)) AS Cycle,

in a master calender 

 

View solution in original post

1 Reply
anwarbham
Contributor III
Contributor III
Author

I managed to get it working 

using the below 

Dual('C' & Ceil(Month(Addmonths(%Calendar_Key, $(i)))/4), Ceil(Month(Addmonths(%Calendar_Key, $(i)))/4)) AS Cycle,

in a master calender