Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

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

Tags (2)
1 Solution

Accepted Solutions
MVP
MVP

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

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,

6 Replies
MVP
MVP

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

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,

cocosmina
Contributor II

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

Hi,

Try using AddMonth. See below description.

Addmonths function | Qlik Community

Best regards,

Cosmina

amartinez35
Valued Contributor

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

Load

  DateField,

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

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

Not applicable

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

Thanks Sunny !!! It Worked

Not applicable

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

Thanks Cosmina !!!

Not applicable

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

Thanks Aurélien !!!