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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to check two fields in two different records (recursion) ??

hi

i have a problem and want your help ,please

i have this data

Main  header Custom headerdescription  Iddate 
10-1916810-19168-A-A-A-A-CCM3/12/2010 07:37:18
10-1916810-19168-A-BHP1/10/20110 06:49:47
10-1916810-19168-A-A-A-B-BCM23/11/2010 03:05:16
10-1916810-19168-A-A-A-A-B-ACM5/12/2010 02:58:00
10-1916810-19168-A-A-A-A-ERC3/12/2010 07:37:18
10-1916810-19168-A-A-A-A-A-ACM5/12/2010 02:58:18
10-1916810-19168-A-A-ABM3/10/2010 12:17:49
10-1916810-19168-A-A-A-BCM12/10/2010 04:54:13
10-1916810-19168-A-A-A-B-CCM23/11/2010 03:05:16
10-1916810-19168-A-A-A-B-ECM23/11/2010 03:05:16
10-1916810-19168-A-A-A-A-FSC3/12/2010 07:37:18
10-1916810-19168-A-A-A-B-ACM23/11/2010 03:05:16
10-1916810-19168-A-AFB1/10/2010 06:49:16
10-1916810-19168-A-A-A-A-BCM3/12/2010 07:37:18
10-1916810-19168-A-A-A-A-ACM3/12/2010 07:37:18
10-1916810-19168-A-A-A-B-DCM23/11/2010 03:05:16
10-1916810-19168-AHP30/9/2010 08:17:43
10-1916810-19168-A-A-A-B-E-ACM10/1/2011 02:55:31
10-1916810-19168-A-A-A-CRC12/10/2010 04:55:15
10-1916810-19168-A-A-A-A-DCM3/12/2010 07:37:18
10-1916810-19168-A-A-A-ACM12/10/2010 04:53:40

which explain one case of the data

the structure of the data is => each main header has many custom header  => for each

custom header has description id "description id is not unique " and date

my problem is to find the real date for each custom header by using this algorithm

1-for each custom header has the same main header i'll check the description id of the current custom header and one step back custom header not the previous to be clear for example

               1- current custom header => 10-19168-A-A-A-B , the one step back is => 10-19168-A-A-A

               2- current custom header => 10-19168-A-A-A-B-E-A , the one step back is => 10-19168-A-A-A-B-E

                        " one step back mean removing last '-' and the letter after it "

then if the description id

               1- diffrent => then the real date of the current custom header  will be  the date of current custom header

               2- same => then the real date of the current custom header will be  the real date

of  the one step back custom header "which has been found with the same algorithm   "

so the final result will be the following table

Main  headerCustom headerdescription  Iddate  Real  Date
10-1916810-19168-A-A-A-A-CCM3/12/2010 07:37:1812/10/2010 04:53:40
10-1916810-19168-A-BHP1/10/20110 06:49:4730/9/2010 08:17:43
10-1916810-19168-A-A-A-B-BCM23/11/2010 03:05:1612/10/2010 04:54:13
10-1916810-19168-A-A-A-A-B-ACM5/12/2010 02:58:0012/10/2010 04:53:40
10-1916810-19168-A-A-A-A-ERC3/12/2010 07:37:183/12/2010 07:37:18
10-1916810-19168-A-A-A-A-A-ACM5/12/2010 02:58:1812/10/2010 04:53:40
10-1916810-19168-A-A-ABM3/10/2010 12:17:493/10/2010 12:17:49
10-1916810-19168-A-A-A-BCM12/10/2010 04:54:1312/10/2010 04:54:13
10-1916810-19168-A-A-A-B-CCM23/11/2010 03:05:1612/10/2010 04:54:13
10-1916810-19168-A-A-A-B-ECM23/11/2010 03:05:1612/10/2010 04:54:13
10-1916810-19168-A-A-A-A-FSC3/12/2010 07:37:183/12/2010 07:37:18
10-1916810-19168-A-A-A-B-ACM23/11/2010 03:05:1612/10/2010 04:54:13
10-1916810-19168-A-AFB1/10/2010 06:49:161/10/2010 06:49:16
10-1916810-19168-A-A-A-A-BCM3/12/2010 07:37:1812/10/2010 04:53:40
10-1916810-19168-A-A-A-A-ACM3/12/2010 07:37:1812/10/2010 04:53:40
10-1916810-19168-A-A-A-B-DCM23/11/2010 03:05:1612/10/2010 04:54:13
10-1916810-19168-AHP30/9/2010 08:17:4330/9/2010 08:17:43
10-1916810-19168-A-A-A-B-E-ACM10/1/2011 02:55:3112/140/2010 04:54:13
10-1916810-19168-A-A-A-CRC12/10/2010 04:55:1512/10/2010 04:55:15
10-1916810-19168-A-A-A-A-DCM3/12/2010 07:37:1812/10/2010 04:53:40
10-1916810-19168-A-A-A-ACM12/10/2010 04:53:4012/10/2010 04:53:40
8 Replies
lironbaram
Partner - Master III
Partner - Master III

hei

attach is an example of what you asked for

the logic in the script is

creating the previous step key by

concatanting the custom header after removing the last two chars to the description id

then join to theis table the original table

where the key will be the original custom header and desc id

hope its helps you

Not applicable
Author

thanks for you help but the result is not exactly what i want

in the attched photo i pointed to the records which have the problem

to be clear in this record i need the real date is to be tha same as the real date of the one step back "Not the date " so

10-19168   10-19168-A-A-A-A-A-A    CM   05/12/2010 02:58    03/12/2010 07:37      should be

10-19168   10-19168-A-A-A-A-A-A    CM   05/12/2010 02:58    12/10/2010 04:53

10-19168   10-19168-A-A-A-B-E-A   CM   10/01/2011 02:55   23/11/2010 03:05    should be

10-19168   10-19168-A-A-A-B-E-A   CM   10/01/2011 02:55   12/10/2010 04:54


Not applicable
Author

any solution please??

i have the same problem also!

lironbaram
Partner - Master III
Partner - Master III

hei

last try ,

i change the algoritm a little bit

what the script does is creating two keys :

the current key, prev stage key,sorting the table

then it finds the index of the record of the previous key,

and peeking the date if Previous Stage is Exists

on the example Data it works

now you shuld test it on large databut it should work

hope its helps you

Not applicable
Author

Hi,

i'm trying your last solution on my DB

but after finishing loading the script it gives me the following message

"Execution of script fgailed.Reload old data?"

i don't know what's the problem and how to solve such an issue

Note:

before your script i made a load for only 2 tables and there's joining between them

lironbaram
Partner - Master III
Partner - Master III

hei

can you upload

a sample file or just your script

i'll try it on sample data

Not applicable
Author

Hi,

Here is the script

MoveTicketHistory:

LOAD resource_no,

     left(resource_no,2) as ResourceNo,

     move_ticket,

    date_created,

    cust_move_ticket,

     left(cust_move_ticket,len(cust_move_ticket)-2) as StepBack,

     Mainmoveticket

FROM

(qvd);

Inner Join

load Timestamp( MinString(date_created)) as [Creation Date],

cust_move_ticket

Resident MoveTicketHistory

Group by cust_move_ticket;

DataTemp:

load *,

  ResourceNo & cust_move_ticket   as Key,

  ResourceNo & StepBack  as PrevKey

Resident MoveTicketHistory

order by ResourceNo,cust_move_ticket;

drop table MoveTicketHistory;

Data:

LOAd *,

  FieldIndex('Key',PrevKey) as index,

if(FieldIndex('Key',PrevKey)=0,[Creation Date],Peek('NewDate',FieldIndex('Key',PrevKey)-1)) as NewDate

resident DataTemp;

drop Table DataTemp;

Thanks in advance for your help

Not applicable
Author

Hi,

First Create a field with right trimming the last 2 characters of Custom Header Field and name it Main Header field.

Then load a new resident table like

MainHeaderTable:

load Main Header,date resident "HeaderTable"

then join this new MainHeaderTable with HeaderTable

that's all i think

good luck.