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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
nburton78
Creator
Creator

Group by status in load script

I currently have data that comes in like this from an excel document:

Order NumberStatusDate
11012/1/2019
12012/2/2019
13012/2/2019
14012/3/2019
15012/4/2019
16012/6/2019
17012/6/2019
21010/1/2019
22010/2/2019
23010/10/2019
24010/12/2019
25010/14/2019
26010/16/2019
27010/16/2019

 

For each order number I want to load the date it was at a certain status, kinda like this.  

 ten status twentystatusthirtystatus
order Number 112/1/201912/2/201912/2/2019
order Number 210/1/201910/2/201910/10/2019

 

I want to do this in the load script, but i'm not sure how it should be done.  Right now all I have is this:

"LOAD [SO Number]&[Order Type] & ([Line Number]*1000) as [Order Number], [WO
Status] as Status, Min as Date
FROM [LineLevelAnalysisLoader\Updated LLI Files\ALL WO Status.xlsx]
(ooxml, embedded labels, table is [10 WO Sales status]);"

 

 

Labels (2)
1 Solution

Accepted Solutions
Taoufiq_Zarra
MVP
MVP

Generic load will be helpful in this case

InputTable:
LOAD * INLINE [
  Order Number, Status, Date
    1, 10, 1/1/2019
    1, 20, 1/2/2019
    1, 30, 1/3/2019
    1, 35, 1/4/2019
    1, 40, 1/5/2019
    1, 45, 1/6/2019
    1, 50, 1/7/2019
    1, 60, 1/8/2019
    1, 70, 1/9/2019
    2, 10, 2/2/2019
    2, 30, 2/3/2019
    2, 40, 2/4/2019
    2, 45, 2/5/2019
    2, 60, 2/6/2019
    2, 90, 2/7/2019
    2, 95, 2/8/2019
    3, 10, 3/3/2019
    3, 15, 3/4/2019
    3, 20, 3/5/2019
    3, 40, 3/6/2019
    3, 45, 3/7/2019
    3, 90, 3/8/2019
];


GenTable:
Generic Load [Order Number], Status, Date Resident InputTable;

ResultTable:
LOAD Distinct [Order Number] Resident InputTable;

FOR i = 0 to NoOfTables()
  TableList:
  LOAD TableName($(i)) as Tablename AUTOGENERATE 1
  WHERE WildMatch(TableName($(i)), 'GenTable.*');
NEXT i

FOR i = 1 to FieldValueCount('Tablename')
  LET vTable = FieldValue('Tablename', $(i));
  LEFT JOIN (ResultTable) LOAD * RESIDENT [$(vTable)];
  DROP TABLE [$(vTable)];
NEXT i

 

Capture.PNG

 

Regards,

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

4 Replies
Taoufiq_Zarra
MVP
MVP

Hi,

on behalf of the great @sunny_talwar (MVP),  I propose to you the solution he proposed:

 

Table:
LOAD *,
	 If([Order Number] = Previous([Order Number]), RangeSum(Peek('StatusNum'), 1), 1) as StatusNum;

LOAD * INLINE [
    Order Number, Status, Date
    1, 10, 12/1/2019
    1, 20, 12/2/2019
    1, 30, 12/2/2019
    1, 40, 12/3/2019
    1, 50, 12/4/2019
    1, 60, 12/6/2019
    1, 70, 12/6/2019
    2, 10, 10/1/2019
    2, 20, 10/2/2019
    2, 30, 10/10/2019
    2, 40, 10/12/2019
    2, 50, 10/14/2019
    2, 60, 10/16/2019
    2, 70, 10/16/2019
];

FinalTable:
LOAD Distinct [Order Number]
Resident Table;

FOR i = 1 to FieldValueCount('StatusNum')
	
	LET vField = FieldValue('StatusNum', $(i));
	
	Left Join (FinalTable)
	LOAD [Order Number],
		 Date as [Status $(vField)]
	Resident Table
	Where StatusNum = $(vField);
	
NEXT i;

DROP Table Table;

the result:

datt.PNG

 

Cheers,

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
nburton78
Creator
Creator
Author

this is very close, however what I didn't mention and probably should have mentioned is that an order may not go through all the statuses.  for example, 

1101/1/2019
1201/2/2019
1301/3/2019
1351/4/2019
1401/5/2019
1451/6/2019
1501/7/2019
1601/8/2019
1701/9/2019
2102/2/2019
2302/3/2019
2402/4/2019
2452/5/2019
2602/6/2019
2902/7/2019
2952/8/2019
3103/3/2019
3153/4/2019
3203/5/2019
3403/6/2019
3453/7/2019
3903/8/2019

 

so the data would look like this:

 1015203035404550607090
11/1/2019 1/2/20191/3/20191/4/20191/5/20191/6/20191/7/20191/8/20191/9/2019 
22/2/2019  2/3/2019 2/4/20192/5/2019 2/6/20192/7/20192/8/2019
33/3/20193/4/20193/5/2019  3/6/20193/7/2019   3/8/2019

 

Also, the name of the status is somewhat important.  

Taoufiq_Zarra
MVP
MVP

Generic load will be helpful in this case

InputTable:
LOAD * INLINE [
  Order Number, Status, Date
    1, 10, 1/1/2019
    1, 20, 1/2/2019
    1, 30, 1/3/2019
    1, 35, 1/4/2019
    1, 40, 1/5/2019
    1, 45, 1/6/2019
    1, 50, 1/7/2019
    1, 60, 1/8/2019
    1, 70, 1/9/2019
    2, 10, 2/2/2019
    2, 30, 2/3/2019
    2, 40, 2/4/2019
    2, 45, 2/5/2019
    2, 60, 2/6/2019
    2, 90, 2/7/2019
    2, 95, 2/8/2019
    3, 10, 3/3/2019
    3, 15, 3/4/2019
    3, 20, 3/5/2019
    3, 40, 3/6/2019
    3, 45, 3/7/2019
    3, 90, 3/8/2019
];


GenTable:
Generic Load [Order Number], Status, Date Resident InputTable;

ResultTable:
LOAD Distinct [Order Number] Resident InputTable;

FOR i = 0 to NoOfTables()
  TableList:
  LOAD TableName($(i)) as Tablename AUTOGENERATE 1
  WHERE WildMatch(TableName($(i)), 'GenTable.*');
NEXT i

FOR i = 1 to FieldValueCount('Tablename')
  LET vTable = FieldValue('Tablename', $(i));
  LEFT JOIN (ResultTable) LOAD * RESIDENT [$(vTable)];
  DROP TABLE [$(vTable)];
NEXT i

 

Capture.PNG

 

Regards,

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
nburton78
Creator
Creator
Author

Thank you that is Perfect!