Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Our next Qlik Insider session will cover new key capabilities. Join us August 11th REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
tamilarasu

Last Two Month Names in Load Script

Hi All,

I want to load last two months data into my application. I just want to create a table which should stores the last two month names in below format. Say for example I have a variable called "vEndingMonth" and the month name stored as "Sep 2015". I want to create a table (by using the above variable) which should contains below month names.

Sep 2015

Aug 2015

July 2015

I'll use the above table when loading QVD's. I wish to use direct file names in my load script instead of looping through all QVD's.

Thank you in advance.

1 Solution

Accepted Solutions
Digvijay_Singh
Master III
Master III

You can use below script -

Let vEndingMonth = Date(MakeDate(2015,09,01),'MMM YYYY');

Let vThreemonths = vEndingMonth &'_'& Date(AddMonths(vEndingMonth,-1),'MMM YYYY') &'_' &Date(AddMonths(vEndingMonth,-2),'MMM YYYY');

Month:

Load subField('$(vThreemonths)','_') as Date Autogenerate(1);

View solution in original post

4 Replies
SreeniJD
Specialist
Specialist

Hi Tamil Nagaraj,

There are multiple ways to achieve this. Let me suggest one way..you can create two columns like prev_month, prev_month-1 and with addmonths() function you can substract -1 for previous month and -2 for previous to previous month. with Date# function you can get the desired format..

HTH

Sreeni

Digvijay_Singh
Master III
Master III

You can use below script -

Let vEndingMonth = Date(MakeDate(2015,09,01),'MMM YYYY');

Let vThreemonths = vEndingMonth &'_'& Date(AddMonths(vEndingMonth,-1),'MMM YYYY') &'_' &Date(AddMonths(vEndingMonth,-2),'MMM YYYY');

Month:

Load subField('$(vThreemonths)','_') as Date Autogenerate(1);

View solution in original post

tamilarasu
Author

Hi Jd Sreeni,

Thanks for the suggestion and it's working fine. But, we need to fetch data from three columns. My expectation is all values in a single field and single table.

Hi DigVijay Singh,

I just modified the your code a bit. It's not taking previous months due to data format problem.

Let vThreemonths = '$(vEndingMonth)' &'_'& MonthName(Addmonths(Date#('$(vEndingMonth)','MMM YYYY'),-1)) &'_' &MonthName(Addmonths(Date#('$(vEndingMonth)','MMM YYYY'),-2));

Month:

Load subField('$(vThreemonths)','_') as Date Autogenerate(1);

Thanks to both of you. Have a nice day.cheerful-cat-face-smiley-emoticon.gif

tamilarasu
Author

Just tried this and working like expected.


FOR i=-2 to 0 Step 1

MonthTemp:

LOAD MonthName(Addmonths(Date#('$(vEndingMonth)','MMM YYYY'),$(i))) as Month AutoGenerate(1);

NEXT