Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
rakeshkumar1890
Creator
Creator

Logical Condition

Hello everyone,

Need your help to find out this logical condition on script.

Perference:

  • First Preference on Category : Supply Issue
  • Second Preference on Category : forecast
  • Third Preference on Category : Others categories

Check 1 :Per OrderLine on longestime, check category with given preference. 

Check 2 :Per OrderLine on longestime, check category with given preference. If same category more than 1 then check into OrderNo counts. Maximum no. of counts should be output

Table:

OrderLinePartsLongestTimeCategoryOrderNo.
CET0578P2413supplier issue304
CET0578P2413forecast305
CET0578P0518Supply Issue304
CET0578P1918forecast100
     
NIM0578P2413supplier issue304
NIM0578P2413forecast305
NIM0578P2418supplier issue304
NIM0578P2418invalid reason code246
NIM0578P2418forecast304
     
PCT0020P1810supplier issue685
PCT0020P0718forecast370
PCT0020P4118supplier issue938
PCT0020P6318invalid reason code938
PCT0020P7218forecast938
PCT0020P9218forecast370
PCT0020P2510supplier issue685
PCT0020P1018Supply Issue290
PCT0020P1418supplier issue564
PCT0020P3018invalid reason code564
PCT0020P5618Supply Issue564
PCT0020P9018Supply Issue290
     
PCT0950P013supplier issue685
PCT0950P032supplier issue938
PCT0950P025forecast200
PCT0950P045invalid reason code938
PCT0950P055forecast938
PCT0950P065forecast370
     
PCT0389P013Bcom685
PCT0389P034supplier issue938
PCT0389P636invalid reason code938
PCT0389P1912NA938
PCT0389P3112Maintenance938
PCT0389P2212Daily370

 

Output Result:     Logics

OrderLinePartsLongestTimeCategoryOrderNo.Remark
CET0578P0518Supply Issue304Result was came due to first preference category - Supply Issue
NIM0578P2418forecast304Result was came due to second preference category - forecast
PCT0020P5618Supply Issue564Result was came due to more than 1 Supply Issue on each orderline PCT0020 at longest time 18,  then I checked to Order No. 564 more than others on longest time ( I checked only "Supply Issue" not to forecast because Supply Issue is first preference
PCT0950P055forecast938Result was came due to more than 1 forecast on each orderline PCT0950 at longest time 5,  then I checked to Order No. 564 more than others in forecast on longest time
PCT0389P1912NA938Result was came due to third preference --  Checked Supply Issue or Forecast are there or not, If not then nothing to check.
PCT0389P3112Maintenance938
PCT0389P2212Daily370

 

Thanks to everyone for your input. I am waiting for the output result.

Please feel to reply if any doubts.

Kind Regards

1 Solution

Accepted Solutions
Taoufiq_Zarra

@rakeshkumar1890  and like this ?

Input:

LOAD * INLINE [
    OrderLine, Parts, Category, OrderNo
    CET0578, P19, forecast, 100
    CET0578, P05, Supply Issue, 304
    NIM0578, P24, forecast, 304
    NIM0578, P24, invalid reason code, 246
    NIM0578, P24, supplier issue, 304
    PCT0020, P07, forecast, 370
    PCT0020, P92, forecast, 370
    PCT0020, P72, forecast, 938
    PCT0020, P30, invalid reason code, 564
    PCT0020, P63, invalid reason code, 938
    PCT0020, P14, supplier issue, 564
    PCT0020, P41, supplier issue, 938
    PCT0020, P10, Supply Issue, 290
    PCT0020, P90, Supply Issue, 290
    PCT0020, P56, Supply Issue, 564
    PCT0389, P22, Daily, 370
    PCT0389, P31, Maintenance, 938
    PCT0389, P19, NA, 938
    PCT0950, P02, forecast, 200
    PCT0950, P04, invalid reason code, 100
    PCT0950, P05, forecast, 100
    PCT0950, P06, forecast, 370
];


left join load OrderLine,concat(Category,'_') as chek1 resident Input group by OrderLine;

left join (Input) load OrderLine,OrderNo,count(OrderNo) as countOrderNo resident Input group by OrderLine,OrderNo;


[SupplyIssueTmp]:
noconcatenate
load * resident Input where Match(Category,'Supply Issue')>0 ;

[SupplyIssue]:
noconcatenate

load OrderLine, FirstSortedValue(Parts,-countOrderNo) as Parts, FirstSortedValue(Category,-countOrderNo) as Category, FirstSortedValue(OrderNo,-countOrderNo) as OrderNo resident SupplyIssueTmp group by OrderLine;

drop table SupplyIssueTmp;


[forecastTmp]:
noconcatenate
load * resident Input where (Match(Category,'forecast')>0 and substringcount(chek1,'Supply Issue')=0) ;


[forecast]:
concatenate(SupplyIssue)

load OrderLine, FirstSortedValue(Parts,-countOrderNo) as Parts, FirstSortedValue(Category,-countOrderNo) as Category, FirstSortedValue(OrderNo,-countOrderNo) as OrderNo  resident forecastTmp group by OrderLine;


drop table forecastTmp;


output:
concatenate(SupplyIssue)
load * resident Input where wildMatch(chek1,'*forecast*','*Supply Issue*')=0;


drop table Input;

drop fields chek1,countOrderNo;
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

8 Replies
Taoufiq_Zarra

@rakeshkumar1890  can you elaborate when we have more than one Supply Issue or forecast

PCT0020P5618Supply Issue564Result was came due to more than 1 Supply Issue on each orderline PCT0020 at longest time 18,  then I checked to Order No. 564 more than others on longest time ( I checked only "Supply Issue" not to forecast because Supply Issue is first preference
PCT0950P055forecast938Result was came due to more than 1 forecast on each orderline PCT0950 at longest time 5,  then I checked to Order No. 564 more than others in forecast on longest time

 

and to be sure Supply Issue not supplier issue ?

Regards,
Taoufiq ZARRA

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

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

Thanks Taoufiq for your input.

Yes it may be more Supply Issue or forecast for each OrderLine, Parts and OrderNo.

Supply Issue and supplier issue are differ. These are two category

 

I want to more filter to raw data. Suppose there is no any longest time. Then in this case need logic on Category preference

Perference:

  • First Preference on Category : Supply Issue
  • Second Preference on Category : forecast
  • Third Preference on Category : Others categories

Check 1 :Per OrderLine, check category with given preference. 

Check 2 :Per OrderLine, check category with given preference. If same category more than 1 then check into OrderNo counts. Maximum no. of counts should be output

We have the raw data like below:

OrderLinePartsCategoryOrderNo
CET0578P19forecast100
CET0578P05Supply Issue304
NIM0578P24forecast304
NIM0578P24invalid reason code246
NIM0578P24supplier issue304
PCT0020P07forecast370
PCT0020P92forecast370
PCT0020P72forecast938
PCT0020P30invalid reason code564
PCT0020P63invalid reason code938
PCT0020P14supplier issue564
PCT0020P41supplier issue938
PCT0020P10Supply Issue290
PCT0020P90Supply Issue290
PCT0020P56Supply Issue564
PCT0950P02forecast200
PCT0950P06forecast370
PCT0950P05forecast938
PCT0950P04invalid reason code938
PCT0389P22Daily370
PCT0389P31Maintenance938
PCT0389P19NA938

 

Output result:

OrderLinePartsCategoryOrderNoRemark
CET0578P05Supply Issue304Result was came due to first preference category - Supply Issue
NIM0578P24forecast304Result was came due to second preference category - forecast
PCT0020P56Supply Issue564Result was came due to more than 1 Supply Issue on each orderline PCT0020,  then I checked to Order No. 564 more than others ( I checked only "Supply Issue" not to forecast because Supply Issue is first preference
PCT0950P05forecast938Result was came due to more than 1 forecast on each orderline PCT0950,  then I checked to Order No. 564 more than others in forecast.
PCT0389P19NA938Result was came due to third preference --  Checked Supply Issue or Forecast are there or not, If not then nothing to check.
PCT0389P31Maintenance938 
PCT0389P22Daily370 
rakeshkumar1890
Creator
Creator
Author

How we can set the logic--

1. First distinct OrderLine then check category for each part no. if found Supply Issue then check how many part no has this category if one time then stop the logic. if more than one time for each part no then we have to check OrderNo. in which highest count of orderno for supply issue.

2. Similarly for forcast.

3. If both(Supply Issue and forecast) are exist in same Orderline then first preference should be - Supply Issue then proceed  with 1 above point.

4. if both are not exist then no logic further it should all partno and category.

 

Taoufiq_Zarra

@rakeshkumar1890  One option :

 

Input:

LOAD * INLINE [
    OrderLine, Parts, Category, OrderNo
    CET0578, P19, forecast, 100
    CET0578, P05, Supply Issue, 304
    NIM0578, P24, forecast, 304
    NIM0578, P24, invalid reason code, 246
    NIM0578, P24, supplier issue, 304
    PCT0020, P07, forecast, 370
    PCT0020, P92, forecast, 370
    PCT0020, P72, forecast, 938
    PCT0020, P30, invalid reason code, 564
    PCT0020, P63, invalid reason code, 938
    PCT0020, P14, supplier issue, 564
    PCT0020, P41, supplier issue, 938
    PCT0020, P10, Supply Issue, 290
    PCT0020, P90, Supply Issue, 290
    PCT0020, P56, Supply Issue, 564
    PCT0950, P02, forecast, 200
    PCT0950, P06, forecast, 370
    PCT0950, P05, forecast, 938
    PCT0950, P04, invalid reason code, 938
    PCT0389, P22, Daily, 370
    PCT0389, P31, Maintenance, 938
    PCT0389, P19, NA, 938
];
left join load OrderLine,concat(Category,'_') as chek1 resident Input group by OrderLine;

[SupplyIssueTmp]:
noconcatenate
load * resident Input where Match(Category,'Supply Issue')>0 ;

[SupplyIssue]:
noconcatenate

load OrderLine, FirstSortedValue(Parts,-OrderNo) as Parts, FirstSortedValue(Category,-OrderNo) as Category, max(OrderNo) as OrderNo resident SupplyIssueTmp group by OrderLine;

drop table SupplyIssueTmp;

[forecastTmp]:
noconcatenate
load * resident Input where (Match(Category,'forecast')>0 and substringcount(chek1,'Supply Issue')=0) ;


[forecast]:
concatenate(SupplyIssue)

load OrderLine, FirstSortedValue(Parts,-OrderNo) as Parts, FirstSortedValue(Category,-OrderNo) as Category, max(OrderNo) as OrderNo resident forecastTmp group by OrderLine;


drop table forecastTmp;


output:
concatenate(SupplyIssue)
load * resident Input where wildMatch(chek1,'*forecast*','*Supply Issue*')=0;


drop table Input;

drop fields chek1;

 

output:

Capture.PNG

Regards,
Taoufiq ZARRA

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

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

Thanks you so much @Taoufiq_Zarra . 

Let me check on my actual data.

rakeshkumar1890
Creator
Creator
Author

@Taoufiq_Zarra : As I checked script you are using Max(OrderNo).

Basically I don't want max(OrderNo).  I need highest count of OrderNo,  lets assume data,

Here 100 came 2 times. but in this 100 category preference is "forecast". resultant highlighted rows.

OrderLinePartsCategoryOrderNoChanged order
PCT0950P02forecast200 
PCT0950P04invalid reason code100Instead of 938 using 100
PCT0950P05forecast100Instead of 938 using 100
PCT0950P06forecast370 

 

Taoufiq_Zarra

@rakeshkumar1890  and like this ?

Input:

LOAD * INLINE [
    OrderLine, Parts, Category, OrderNo
    CET0578, P19, forecast, 100
    CET0578, P05, Supply Issue, 304
    NIM0578, P24, forecast, 304
    NIM0578, P24, invalid reason code, 246
    NIM0578, P24, supplier issue, 304
    PCT0020, P07, forecast, 370
    PCT0020, P92, forecast, 370
    PCT0020, P72, forecast, 938
    PCT0020, P30, invalid reason code, 564
    PCT0020, P63, invalid reason code, 938
    PCT0020, P14, supplier issue, 564
    PCT0020, P41, supplier issue, 938
    PCT0020, P10, Supply Issue, 290
    PCT0020, P90, Supply Issue, 290
    PCT0020, P56, Supply Issue, 564
    PCT0389, P22, Daily, 370
    PCT0389, P31, Maintenance, 938
    PCT0389, P19, NA, 938
    PCT0950, P02, forecast, 200
    PCT0950, P04, invalid reason code, 100
    PCT0950, P05, forecast, 100
    PCT0950, P06, forecast, 370
];


left join load OrderLine,concat(Category,'_') as chek1 resident Input group by OrderLine;

left join (Input) load OrderLine,OrderNo,count(OrderNo) as countOrderNo resident Input group by OrderLine,OrderNo;


[SupplyIssueTmp]:
noconcatenate
load * resident Input where Match(Category,'Supply Issue')>0 ;

[SupplyIssue]:
noconcatenate

load OrderLine, FirstSortedValue(Parts,-countOrderNo) as Parts, FirstSortedValue(Category,-countOrderNo) as Category, FirstSortedValue(OrderNo,-countOrderNo) as OrderNo resident SupplyIssueTmp group by OrderLine;

drop table SupplyIssueTmp;


[forecastTmp]:
noconcatenate
load * resident Input where (Match(Category,'forecast')>0 and substringcount(chek1,'Supply Issue')=0) ;


[forecast]:
concatenate(SupplyIssue)

load OrderLine, FirstSortedValue(Parts,-countOrderNo) as Parts, FirstSortedValue(Category,-countOrderNo) as Category, FirstSortedValue(OrderNo,-countOrderNo) as OrderNo  resident forecastTmp group by OrderLine;


drop table forecastTmp;


output:
concatenate(SupplyIssue)
load * resident Input where wildMatch(chek1,'*forecast*','*Supply Issue*')=0;


drop table Input;

drop fields chek1,countOrderNo;
Regards,
Taoufiq ZARRA

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

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

Big thanks @Taoufiq_Zarra . I got the same solution