Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
dmohanty
Partner - Specialist
Partner - Specialist

Calculate Last 6 months in Load Script?

Hi All,

I have a Month field with 12 months values like = Mar-15, Feb-15, Jan-15, Dec-14, Nov-14 etc.

I want to write a script in Load statement, where it would calculate the Last 6 Months of data dynamically.

Ex- When I select Mar-15, then 6 Months of data(Mar-15 - Oct-14) will be calculated and will be displayed in an Object.

      When I select Feb-15, then 6 Months of data(Feb-15 - Sep-14) will be calculated and will be displayed in an Object.

I tried using the below clause, but its getting calculated for the particular month (Its not becoming dynamic) :

[Month] >= addmonths(date(MonthName(Today(),0), 'MM/DD/YYYY'),-6)
and
[Month]addmonths(date(MonthName(Today(),0), 'MM/DD/YYYY'),0)


So this expression is always calculating the data of latest month and previous 6 months.


Could someone please help this to make dynamic.


Regards!



10 Replies
Anonymous
Not applicable

by doing +2 in script it is giving me all of the monthyear that are in my field. i think some change would be required in script line

i have done subtraction in script line by which i am getting jan14,feb14

year(date)*12-month(date) as monthid,  /* in script

and in an expression i have written 3 by which it is showing me three months

=sum({$ <year=,month=,monthyear=,monthid={">$(=max(monthid)-3)<=$(=max(monthid))"}>}val)

The original script  is

year(date)*12+month(date) as monthid,  /* in script addition done