Qlik Community

Ask a Question

New to QlikView

If you’re new to QlikView, start with this Discussion Board and get up-to-speed quickly.

Announcements
Welcome to our newly redesigned Qlik Community! Read our blog to learn about all the new updates: READ BLOG and REPORTED ISSUES
cancel
Showing results for 
Search instead for 
Did you mean: 
Creator II
Creator II

Flag Yes/No for Last 5 month and field Value

Please help me to flag the table as per the below condition

Last 6 Months and Rank = A & B Flag Yes else No

Capture.JPG

1 Solution

Accepted Solutions
Specialist III
Specialist III

If it's last 5 months from today, you can use :

LOAD *,
if(date#(Year(Date)*10&num(month(Date)),'YYYYMM') >= Date#(AddMonths(date#(Year(Today())*10&num(month(Today())),'YYYYMM'),-6),'M/D/YYYY') and (Rank='A' or Rank='B'),1,0) as FL

INLINE [
    Date, Rank, ID
    1/1/2016, A, 1
    2/1/2016, B, 2
    3/1/2016, C, 3
    5/1/2016, E, 4
    6/1/2016, E, 5
    7/1/2016, D, 6
    8/1/2016, A, 7
    9/1/2016, B, 8
    10/1/2016, E, 9
    11/1/2016, A, 10
    12/1/2016, C, 11
    1/1/2017, C, 12
    2/1/2017, D, 13
    3/1/2017, E, 14
    4/1/2017, E, 15
    5/1/2017, D, 16
    6/1/2017, A, 17
    7/1/2017, B, 18
    8/1/2017, E, 19
    9/1/2017, A, 20
    10/1/2017, C, 21
    11/1/2017, C, 22
    12/1/2017, D, 23
    1/1/2018, E, 24
    2/1/2018, E, 25
    3/1/2018, D, 26
    4/1/2018, A, 27
    5/1/2018, B, 28
    6/1/2018, E, 29
    7/1/2018, A, 30
];

View solution in original post

7 Replies
Specialist II
Specialist II

Is this what you are looking for..

Specialist III
Specialist III

If it's last 5 months from today, you can use :

LOAD *,
if(date#(Year(Date)*10&num(month(Date)),'YYYYMM') >= Date#(AddMonths(date#(Year(Today())*10&num(month(Today())),'YYYYMM'),-6),'M/D/YYYY') and (Rank='A' or Rank='B'),1,0) as FL

INLINE [
    Date, Rank, ID
    1/1/2016, A, 1
    2/1/2016, B, 2
    3/1/2016, C, 3
    5/1/2016, E, 4
    6/1/2016, E, 5
    7/1/2016, D, 6
    8/1/2016, A, 7
    9/1/2016, B, 8
    10/1/2016, E, 9
    11/1/2016, A, 10
    12/1/2016, C, 11
    1/1/2017, C, 12
    2/1/2017, D, 13
    3/1/2017, E, 14
    4/1/2017, E, 15
    5/1/2017, D, 16
    6/1/2017, A, 17
    7/1/2017, B, 18
    8/1/2017, E, 19
    9/1/2017, A, 20
    10/1/2017, C, 21
    11/1/2017, C, 22
    12/1/2017, D, 23
    1/1/2018, E, 24
    2/1/2018, E, 25
    3/1/2018, D, 26
    4/1/2018, A, 27
    5/1/2018, B, 28
    6/1/2018, E, 29
    7/1/2018, A, 30
];

View solution in original post

Creator II
Creator II

Nope,

Yes Means Rank=A, B and Last 5 month

No Means Exclude above and show rest of the values

Specialist II
Specialist II

Check this.

I have added last 6 months, you can change it to 5 months.

Creator II
Creator II

If I click No, it showing everything instead of C,D,E in Rank

Capture.JPG

Specialist II
Specialist II

Check this. I am not sure how you would like to treat the nulls.

Master II
Master II

Try below script?

Hope that helps....?

Table1:

//PrecedingLoad//


load*,

if(Rolling6='1' and NewRanks='Yes','Yes' ,

if(Rolling6='0'and NewRanks='No','No')) as RankFlag;

//PrecedingLoad//

load*,

If( Date > monthstart(addmonths(today(),-5)) and Date <= today(),1,0 ) as Rolling6,

if(Rank='A','Yes',

if(Rank='B','Yes','No')) as NewRanks,

Year(Date) as RankYear,

Month(Date) as RankMonth;


//OriginalLoad//

LOAD * INLINE [

    Date, Rank, ID

    1/1/2016, A, 1

    2/1/2016, B, 2

    3/1/2016, C, 3

    5/1/2016, E, 4

    6/1/2016, E, 5

    7/1/2016, D, 6

    8/1/2016, A, 7

    9/1/2016, B, 8

    10/1/2016, E, 9

    11/1/2016, A, 10

    12/1/2016, C, 11

    1/1/2017, C, 12

    2/1/2017, D, 13

    3/1/2017, E, 14

    4/1/2017, E, 15

    5/1/2017, D, 16

    6/1/2017, A, 17

    7/1/2017, B, 18

    8/1/2017, E, 19

    9/1/2017, A, 20

    10/1/2017, C, 21

    11/1/2017, C, 22

    12/1/2017, D, 23

    1/1/2018, E, 24

    2/1/2018, E, 25

    3/1/2018, D, 26

    4/1/2018, A, 27

    5/1/2018, B, 28

    6/1/2018, E, 29

    7/1/2018, A, 30

];

2018-07-05_150514.png