Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
mtucholski
Creator
Creator

How to make a sub-group based on assumptions.

Hello,

I have a source table which looks like below (columns 1-6). But I need to add some data to it somehow (columns 7-9).

Here is some explanation:

I have an order (1) with plenty of documents (5) where 'Pw' stands for product made and 'Rw' for material used (4). In every order there is a sub order (9) which I'm aware of but there is no simple way to show it.

I know the start date (7) and the end date (8) of the sub order (9) because I know that after every group of documents marked as 'Pw' there will be at least one document marked as 'Rw' (4). So I know that the sub order starts with the first 'Pw' that occurs right after 'Rw' and it ends with the last 'Rw' that occurs right before another 'Pw'.

The question is how to do it in QlikView load script :-). I will apprecieate any help. Thank you.

        

123456789
order_nodatetimedocumentdocument_nomaterial_codefromtosub_order_no
2291852018-02-2622:07:28Pw  1863862224953472018-02-26 22:07:282018-02-26 22:08:371
2291852018-02-2622:08:00Rw  1863861924781982018-02-26 22:07:282018-02-26 22:08:371
2291852018-02-2622:08:18Rw  1863861624944522018-02-26 22:07:282018-02-26 22:08:371
2291852018-02-2622:08:37Rw  1863861024930082018-02-26 22:07:282018-02-26 22:08:371
2291852018-02-2622:23:40Pw  1863860724953542018-02-26 22:23:402018-02-26 22:24:282
2291852018-02-2622:24:09Rw  1863860424930082018-02-26 22:23:402018-02-26 22:24:282
2291852018-02-2622:24:28Rw  1863860124944522018-02-26 22:23:402018-02-26 22:24:282
2291852018-02-2623:50:23Pw  1863859824953902018-02-26 23:50:232018-02-26 23:51:473
2291852018-02-2623:51:43Pw  1863858624944522018-02-26 23:50:232018-02-26 23:51:473
2291852018-02-2623:51:44Rw  1863858324930082018-02-26 23:50:232018-02-26 23:51:473
2291852018-02-2623:51:47Rw  1863852824944482018-02-26 23:50:232018-02-26 23:51:473
2291852018-02-2700:22:17Pw  1863852524954162018-02-27 00:22:172018-02-27 00:23:454
2291852018-02-2700:23:40Rw  1863852224944482018-02-27 00:22:172018-02-27 00:23:454
2291852018-02-2700:23:41Rw  1863851924930082018-02-27 00:22:172018-02-27 00:23:454
2291852018-02-2700:23:45Rw  1863840524628512018-02-27 00:22:172018-02-27 00:23:454
2291852018-02-2700:57:17Pw  1863836824954402018-02-27 00:57:172018-02-27 00:59:475
2291852018-02-2700:58:36Pw  1863836524930082018-02-27 00:57:172018-02-27 00:59:475
2291852018-02-2700:58:55Pw  1863836224894732018-02-27 00:57:172018-02-27 00:59:475
2291852018-02-2700:59:47Rw  1863827224628512018-02-27 00:57:172018-02-27 00:59:475
10 Replies
mtucholski
Creator
Creator
Author

Hi,

just add "and previous(document)<>document" in first "where" and we are almost there :-). So the final code is:

Submap:

Mapping Load 

order_no&'|'&date&'|'&time&'|'&document as key,

RowNo() as temp_sub_order_no

FROM 

[X]  (x)

where document='Pw' and previous(document)<>document

;

Table1:

Load

order_no,

date,

time,

document,

document_no,

material_code,

ApplyMap('Submap', key, null()) as sub_order_no

;

LOAD

order_no&'|'&date&'|'&time&'|'&document as key,

order_no,

date,

time,

document,

document_no,

material_code

FROM 

[X]  (x)

;

NoConcatenate

New:

Load

order_no,

date,

time,

document,

document_no,

material_code,

If( isnull(sub_order_no), peek(sub_order_no),sub_order_no )as sub_order_no

Resident Table1

order by date, time

;

Drop table Table1

;

There is some exceptions which I don't want to bring in here - just have to work it out by myself . Anyway, thank you for your help!