Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
racer25
Creator
Creator

LOAD MAX and 2nd MAX and Data In Between

Hi All,

I am looking to load some information from a 20 year old data table; I am looking to get the last "R" transaction and also every PLY_VERNO back to the previous R or N record. Highlighted in the table below in red are the rows I wish to load. As you can in 0023879 we capture 6 rows whereas 0023878 only 2.

I have thought about this and have to admit to not really having much on how to deliver this. I'd appreciate some help on this please.

Thanks,

Rob

 

PLY_COVERNUMBERPLY_VERNOPLY_TRANSACTIONTYPE
0023877005E
0023877006R
0023877007R
0023877008N
0023877009E
0023877010R
0023877010L
0023878000N
0023878001R
0023878002R
0023878003R
0023878004R
0023878005R
0023878006R
0023878007L
0023879014R
0023879015R
0023879016R
0023879017E
0023879018R
0023879019R
0023879020R
0023879021E
0023879022E
0023879023E
0023879024E
0023879025R
Labels (1)
1 Solution

Accepted Solutions
settu_periasamy
Master III
Master III

Maybe there is an easy method. I tried this..

T1:

LOAD * INLINE [

    PLY_COVERNUMBER, PLY_VERNO, PLY_TRANSACTIONTYPE

    0023877, 5, E

    0023877, 6, R

    0023877, 7, R

    0023877, 8, N

    0023877, 9, E

    0023877, 10, R

    0023877, 10, L

    0023878, 0, N

    0023878, 1, R

    0023878, 2, R

    0023878, 3, R

    0023878, 4, R

    0023878, 5, R

    0023878, 6, R

    0023878, 7, L

    0023879, 14, R

    0023879, 15, R

    0023879, 16, R

    0023879, 17, E

    0023879, 18, R

    0023879, 19, R

    0023879, 20, R

    0023879, 21, E

    0023879, 22, E

    0023879, 23, E

    0023879, 24, E

    0023879, 25, R

];

NoConcatenate

T2:

LOAD PLY_COVERNUMBER

  ,Max(PLY_VERNO) as PLY_VERNO

  ,PLY_TRANSACTIONTYPE,'Max' as Temp

Resident T1 Where PLY_TRANSACTIONTYPE='R'

Group by PLY_COVERNUMBER,PLY_TRANSACTIONTYPE

Order By PLY_COVERNUMBER,PLY_VERNO;

Concatenate(T2)

LOAD PLY_COVERNUMBER

  ,Max(PLY_VERNO,2) as PLY_VERNO,

  PLY_TRANSACTIONTYPE,'Max2' as Temp

Resident T1 Where PLY_TRANSACTIONTYPE='R'

Group by PLY_COVERNUMBER,PLY_TRANSACTIONTYPE

Order By PLY_COVERNUMBER,PLY_VERNO;

Left Join(T1)

LOAD * Resident T2;

DROP Table T2;

NoConcatenate

T3:

LOAD PLY_COVERNUMBER

  ,PLY_VERNO

  ,PLY_TRANSACTIONTYPE

  ,if(Temp='Max' or Temp='Max2','Yes',

  if(Peek(Temp1)='Yes' and PLY_COVERNUMBER=Previous(PLY_COVERNUMBER) and Previous(Temp)<>'Max','Yes','No') ) as Temp1

Resident T1;

DROP Table T1;

NoConcatenate

Final:

LOAD PLY_COVERNUMBER,

  PLY_VERNO,

  PLY_TRANSACTIONTYPE

Resident T3 Where Temp1='Yes';

DROP Table T3;

Capture.JPG

View solution in original post

1 Reply
settu_periasamy
Master III
Master III

Maybe there is an easy method. I tried this..

T1:

LOAD * INLINE [

    PLY_COVERNUMBER, PLY_VERNO, PLY_TRANSACTIONTYPE

    0023877, 5, E

    0023877, 6, R

    0023877, 7, R

    0023877, 8, N

    0023877, 9, E

    0023877, 10, R

    0023877, 10, L

    0023878, 0, N

    0023878, 1, R

    0023878, 2, R

    0023878, 3, R

    0023878, 4, R

    0023878, 5, R

    0023878, 6, R

    0023878, 7, L

    0023879, 14, R

    0023879, 15, R

    0023879, 16, R

    0023879, 17, E

    0023879, 18, R

    0023879, 19, R

    0023879, 20, R

    0023879, 21, E

    0023879, 22, E

    0023879, 23, E

    0023879, 24, E

    0023879, 25, R

];

NoConcatenate

T2:

LOAD PLY_COVERNUMBER

  ,Max(PLY_VERNO) as PLY_VERNO

  ,PLY_TRANSACTIONTYPE,'Max' as Temp

Resident T1 Where PLY_TRANSACTIONTYPE='R'

Group by PLY_COVERNUMBER,PLY_TRANSACTIONTYPE

Order By PLY_COVERNUMBER,PLY_VERNO;

Concatenate(T2)

LOAD PLY_COVERNUMBER

  ,Max(PLY_VERNO,2) as PLY_VERNO,

  PLY_TRANSACTIONTYPE,'Max2' as Temp

Resident T1 Where PLY_TRANSACTIONTYPE='R'

Group by PLY_COVERNUMBER,PLY_TRANSACTIONTYPE

Order By PLY_COVERNUMBER,PLY_VERNO;

Left Join(T1)

LOAD * Resident T2;

DROP Table T2;

NoConcatenate

T3:

LOAD PLY_COVERNUMBER

  ,PLY_VERNO

  ,PLY_TRANSACTIONTYPE

  ,if(Temp='Max' or Temp='Max2','Yes',

  if(Peek(Temp1)='Yes' and PLY_COVERNUMBER=Previous(PLY_COVERNUMBER) and Previous(Temp)<>'Max','Yes','No') ) as Temp1

Resident T1;

DROP Table T1;

NoConcatenate

Final:

LOAD PLY_COVERNUMBER,

  PLY_VERNO,

  PLY_TRANSACTIONTYPE

Resident T3 Where Temp1='Yes';

DROP Table T3;

Capture.JPG