Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How should I create new field in load script (select last 12 month date)?

Dear Team,

I want to create new field in load script using if else.

For example field "Last12Month", it will only select last 12 month period exclude this month.

I want to create few field:

a) Last12Month

b) Last24Month

c) Last36Month.

Please help.

Thanks.

period script.PNG

period table.PNG

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Dear Massimo,

Thanks. I do it like this.

    if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-35),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last36Month,

   

      if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-23),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last24Month,

   

      if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-11),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last12Month,

   

      if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-5),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last6Month,

View solution in original post

2 Replies
maxgro
MVP
MVP

An option could be

https://help.qlik.com/en-US/sense/September2017/Subsystems/Hub/Content/Scripting/DateAndTimeFunction...

// last 12

InYear(Date#(Period, 'YYYYMMDD'), AddMonths(MonthStart(today()), -1), 0, Month(today())) as Last12Month

// last 24

InYear(Date#(Period, 'YYYYMMDD'), AddMonths(MonthStart(today()), -1), 0, 5) or InYear(d, AddMonths(MonthStart(today()), -1), -1, 5) as Last24Month


Anonymous
Not applicable
Author

Dear Massimo,

Thanks. I do it like this.

    if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-35),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last36Month,

   

      if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-23),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last24Month,

   

      if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-11),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last12Month,

   

      if(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')> AddMonths(MonthStart(Today()),-5),(Date(date#(Period,'YYYYMMDD'),'DD-MMM-YYYY')))

   

    as Last6Month,