Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to find last 3, 6, 12 months ???

Hi in my script i need to include a field such as month values ,which should hold the last 3months , last6months, last 12 moths(3 colums).. When i click last 3 months the calculation should change.. I need it in script

For example i have used the below script for finding QTR1, 2, 3, 4 , simillarly i want for last3 months , 6 , 12 months

If(Num(month([Session Start]))<=3, 'Q1-' & Year([Session Start]),

If(Num(month([Session Start]))<=6, 'Q2-' & Year([Session Start]),

  If(Num(month([Session Start]))<=9, 'Q3-' & Year([Session Start]),

   If(Num(month([Session Start]))<=12, 'Q4-' & Year([Session Start])

    )

     )

      )

       ) as Qtr,

1 Reply
jagan
Luminary Alumni
Luminary Alumni

Hi,

Use the following expression

For last 3 Months:

=Sum({<DateField={'>=$(=MonthStart(Max(DateField), -2))<=$(=MonthEnd(Max(DateField)))'}>} Sales)

For last 6 Months:

=Sum({<DateField={'>=$(=MonthStart(Max(DateField), -5))<=$(=MonthEnd(Max(DateField)))'}>} Sales)

For last 12 Months:

=Sum({<DateField={'>=$(=MonthStart(Max(DateField), -11))<=$(=MonthEnd(Max(DateField)))'}>} Sales)

Regards,

Jagan.