Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I need help to get last quarter data dynamically
Hi,
My Qlik report is a quarterly report and this report will get refreshed every quarter. When i am loading the data from database , I want to pull last quarter data dynamically in load script itself. For ex: We are currently in Last quarter of 2022 , Now I want to pull the last quarter data which is 2021-07-01(July) to 2021-09-30(Sep) . Next when Qlik report get refreshed on Jan01 2022 then Dynamically it should pull last quarter data which is from Oct 01-2021 to Dec 31 -2021 data. Can some one help me how to achieve this in load script. Thanks!
Are you only interested in the current quarter information? So would a full load of the current quarter be enough or do you want to load incrementally? If you only need the full load of the current quarter you could do something like this:
LET vToday = Today();
LET vCurrentYear = Year($(vToday));
LET vCurrentMonth = Month($(vToday));
LET vCurrentQuarter = Ceil($(vCurrentMonth) / 3);
LET vQuarterStart = MakeDate($(vCurrentYear), (($(vCurrentQuarter)-1)*3)+1, 1);
LET vQuarterEnd = MonthEnd(MakeDate($(vCurrentYear), $(vCurrentQuarter)*3, 1));
LOAD
*
FROM [your_data_source]
WHERE YourDateField >= $(vQuarterStart) AND YourDateField <= $(vQuarterEnd);
Are you only interested in the current quarter information? So would a full load of the current quarter be enough or do you want to load incrementally? If you only need the full load of the current quarter you could do something like this:
LET vToday = Today();
LET vCurrentYear = Year($(vToday));
LET vCurrentMonth = Month($(vToday));
LET vCurrentQuarter = Ceil($(vCurrentMonth) / 3);
LET vQuarterStart = MakeDate($(vCurrentYear), (($(vCurrentQuarter)-1)*3)+1, 1);
LET vQuarterEnd = MonthEnd(MakeDate($(vCurrentYear), $(vCurrentQuarter)*3, 1));
LOAD
*
FROM [your_data_source]
WHERE YourDateField >= $(vQuarterStart) AND YourDateField <= $(vQuarterEnd);