Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Need to create a flag that will give me value = 1 when dateField is last month date

Hi Team,

Request you to please help me create a flag in Qlikview Script that will show value =1 when Date is Last Month Date

I have created a flag but now not working because of change in Year from 2016 to 2017

if(Month(date(DateField))=month(today())-1,1,0) as isLastMonth...............This is not working

Similarly

For last previous 3 months I was using

if(Month(date(DateField))>=month(today())-3,1,0) as isLast3Month..This is also not working

Can anyone please help me create similar flag

Example

Say today date is 01/18/2017

   

DateFieldIsLastMonthIsPrevious3Month
1/18/201700
12/19/201711
11/21/201601
10/24/201601
9/25/201601

Regards

Siddharth

1 Solution

Accepted Solutions
sunny_talwar

May be like this:

If(MonthStart(DateField) = MonthStart(Today(), -1), 1, 0) as isLastMonth,

If(MonthStart(DateField) >= MonthStart(Today(), -3) and MonthStart(DateField) <= MonthStart(Today(), -1), 1, 0) as isLast3Month,

View solution in original post

6 Replies
sunny_talwar

May be like this:

If(MonthStart(DateField) = MonthStart(Today(), -1), 1, 0) as isLastMonth,

If(MonthStart(DateField) >= MonthStart(Today(), -3) and MonthStart(DateField) <= MonthStart(Today(), -1), 1, 0) as isLast3Month,

Anonymous
Not applicable
Author

Hi,

Try using AddMonth. See below description.

Addmonths function | Qlik Community

Best regards,

Cosmina

Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Load

  DateField,

  InMonth(DateField, Today(), -1) as IsLastMonth,

  InMonth(DateField, Today(), - 3) as IsPrevious3Month

Help users find answers! Don't forget to mark a solution that worked for you!
Not applicable
Author

Thanks Sunny !!! It Worked

Not applicable
Author

Thanks Cosmina !!!

Not applicable
Author

Thanks Aurélien !!!