Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
upaliwije
Creator II
Creator II

SeqNo

Hi

I have following data in my Data model

  

POLICY_NOPeriod
1M00131A000010628-07-14
1M00131A000008223-01-14
1M00131A000008223-01-15
1M00131A000012016-10-14
1M00131A000012522-10-14
1M00131A000012522-10-15
1M00131A000012512-11-16
1M00131A000009104-04-14
1M00131A000009104-04-15
1M00111A00004029-08-14
1M00131A000008117-01-14
1M00131A000011020-08-14
1M00131A000011020-08-15
1M00131A000011020-08-16
1M00131A000011020-08-17

I want add another column (seqNo) as shown below. That is when period of particular policy_no changes seqno should beincrsed and recorded

   

POLICY_NOPeriodSeqno
1M00131A000010628-07-141
1M00131A000008223-01-141
1M00131A000008223-01-152
1M00131A000012016-10-141
1M00131A000012522-10-141
1M00131A000012522-10-152
1M00131A000012512-11-163
1M00131A000009104-04-141
1M00131A000009104-04-152
1M00111A00004029-08-141
1M00131A000008117-01-141
1M00131A000011020-08-141
1M00131A000011020-08-152
1M00131A000011020-08-163
1M00131A000011020-08-174

Pls help me how to write my script to obtain above result

17 Replies
anushree1
Specialist II
Specialist II

Hi Sunny,

I do not seem to understand why preceding load would not work.

I did try that and it looks all well to me.

Could you please refer the attachment and share your comments

sunny_talwar

You did not have preceding load and that is why both RowNo and RecNo worked, try this:

Temp:

LOAD *,

  0 as Dummy;

LOAD *,

AutoNumber(RowNo(),POLICY_NO) AS SeqNo1,

AutoNumber(RecNo(),POLICY_NO) AS SeqNo2;

LOAD POLICY_NO,

    Period

FROM

[https://community.qlik.com/thread/253566]

(html, codepage is 1252, embedded labels, table is @1);

Now RecNo() should still work, but AFAIK RowNo() won't work anymore....

sunny_talwar

Tested it here:

Table:

LOAD *,

  0 as Dummy;

LOAD *,

AutoNumber(RowNo(),POLICY_NO&'RowNo') AS SeqNo1,

AutoNumber(RecNo(),POLICY_NO&'RecNo') AS SeqNo2;

LOAD * INLINE [

    POLICY_NO, Period

    1M00131A0000106, 28-07-14

    1M00131A0000082, 23-01-14

    1M00131A0000082, 23-01-15

    1M00131A0000120, 16-10-14

    1M00131A0000125, 22-10-14

    1M00131A0000125, 22-10-15

    1M00131A0000125, 12-11-16

    1M00131A0000091, 04-04-14

    1M00131A0000091, 04-04-15

    1M00111A000040, 29-08-14

    1M00131A0000081, 17-01-14

    1M00131A0000110, 20-08-14

    1M00131A0000110, 20-08-15

    1M00131A0000110, 20-08-16

    1M00131A0000110, 20-08-17

];

Capture.PNG

tresesco
MVP
MVP

Yes, it's another aspect of RowNo()/RecNo() usage consideration. However, it still holds that if the records get filtered in where clause, recno() would not give the expected output.

Anil_Babu_Samineni

Tested Done

Capture.PNG

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
upaliwije
Creator II
Creator II
Author

Hi Sunny,

When I did as advised by you I get seqno 1,2 for the same policy period as shown below. Can you pls advise how to correct it

POLICY_NOPOL_PERIOD_TOSeqno
1M00151A000019711-02-16 1
1M00151A000019711-02-16 2
1M00151A000019711-02-17 3
1M00151A000019711-02-18 4

Correct numbering should be (seqno)1,1,2,3

sunny_talwar

Try this:

Table:

LOAD * INLINE [

    POLICY_NO, POL_PERIOD_TO

    1M00151A0000197, 11-02-16

    1M00151A0000197, 11-02-16

    1M00151A0000197, 11-02-17

    1M00151A0000197, 11-02-18

];

FinalTable:

LOAD POLICY_NO,

  POL_PERIOD_TO,

If(POLICY_NO = Previous(POLICY_NO),

  If(POL_PERIOD_TO = Previous(POL_PERIOD_TO), Peek('Seqno'), RangeSum(Peek('Seqno'), 1)), 1) as Seqno

Resident Table

Order By POLICY_NO, POL_PERIOD_TO;

DROP Table Table;

upaliwije
Creator II
Creator II
Author

Thanks . That is what I want exactly