Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
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

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

6 Replies
JordyWegman
Partner - Master
Partner - Master

Hi Rakesh,

You will need to create some indicators for this in order to work properly. Your script should look something like this:

// Create a key for joining data later
tmpTable:
Load
   OrderLine & '|' & max(LongestTime)   as %OrderLineMaxTime,
   OrderLine & '|' & Category           as %OrderLineCategory  
   *    
From {YourSource} (qvd):

// Create key for join and get the max time. Create the indicator for later
Left Join (tmpTable)
Load
   OrderLine & '|' & max(LongestTime)   as %OrderLineMaxTime
   max(LongestTime) as LongestTime
   1                as _indLongestTime     
From {YourSource} (qvd)
Group by OrderLine;

//  You also need to know which one has the highest count for the ones with the longest time.
Noconcatenate:
Load
   OrderLine & '|' & Category   as %OrderLineCategory   
   Max(OrderNo.)                as _cntOrderNo
   1                            as _indCountOrderNo
Resident tmpTable
Where _indLongestTime = 1
Group by OrderLine, Category;

// Then load the table and get the indicators:
Load
*
Resident tmpTable
Where _indCountOrderNo = 1 and _indLongestTime = 1;

 Jordy

Climber

Work smarter, not harder
rakeshkumar1890
Creator
Creator
Author

Thanks  Wegman for your inputs.

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

@JordyWegman  : Your comment -- 

// You also need to know which one has the highest count for the ones with the longest time

It should be Highest count(OrderNo) for each OrderLine according the category preference. 

No need to Max(OrderNo) -- It may be any (Highest count).

Taoufiq_Zarra

https://community.qlik.com/t5/New-to-QlikView/Logical-Condition/td-p/1751652

 

@rakeshkumar1890  can you check

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") 😉
Taoufiq_Zarra

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