Skip to content

Instantly share code, notes, and snippets.

@countnazgul
Last active April 17, 2022 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save countnazgul/9fecb31092ac14a52b06 to your computer and use it in GitHub Desktop.
Save countnazgul/9fecb31092ac14a52b06 to your computer and use it in GitHub Desktop.
[Generate all previous months] For each month in the given months list, generate all previous months #qlik #qliksense #qlikview #script
Raw:
Load * Inline [
Month
2014-01
2014-02
2014-03
2014-04
2014-05
];
NoConcatenate
TempTable1:
Load Distinct
date(Date#(Month, 'YYYY-MM')) as Month
Resident
Raw
Order By
Month
;
Drop Table Raw;
let vMinMonth = date(FieldValue('Month',1));
for i = 1 to FieldValueCount('Month')
let vMonth = FieldValue('Month',i);
let vMonthDiff = ((year(date('$(vMonth)'))*12)+month(date('$(vMonth)'))) - (((year(date('$(vMinMonth)'))*12)+month(date('$(vMinMonth)')))) ;
for a = 0 to vMonthDiff
Test:
Load
'$(vMonth)' as Month,
AddMonths(date('$(vMonth)'), -$(a)) as PreviousMonths
AutoGenerate(1);
next
next
Drop Table TempTable1;
let a = Null();
let i = Null();
let vMonthDiff = Null();
let vMonth = Null();
let vMinMonth = Null();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment