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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
priya945
Creator
Creator

Check and count the matched cases

Hi All,

My data looks like

CaseReason
1Case A; Case B
2Case B
3Case C; Case A
4Case D; Case B
5Case A; Case C
6Case B;Case D
7Case E

 

Logic:   out of many cases in Reason field, i need to check if the case is present in a list(Case A,Case B,Case D)
& mark 1 against it if the case is present in Reason field and o for others.
Also if there are two cases are present in Reason filed then i need to mark 1 against the first case only

Finally count the 1's in frontend

CaseReasonCase ACase BCase D
1Case A; Case B100
2Case B010
3Case C; Case A100
4Case D; Case B001
5Case A; Case C100
6Case B;Case D010
7Case E000
  321

 

Thanks in advance

2 Solutions

Accepted Solutions
Taoufiq_Zarra

 

Data :

LOAD rowno() as IDcase,trim(subfield(Reason,';')) as Cases,* INLINE [
    Case,Reason
    1, Case A; Case B
    2, Case B
    3, Case C; Case A
    4, Case D; Case B
    5, Case A; Case C
    6, Case B;Case D
    7, Case E
];

FirstSortedValue:
noconcatenate
LOAD Case,FirstSortedValue(Cases, IDcase) as FirstCase Resident Data  where match(Cases,'Case A','Case B','Case D')>0 Group By Case ;
left join load * resident Data;

drop table Data;

output:
noconcatenate
load Case,Reason,if(FirstCase='Case A',1,0) as "Case A",if(FirstCase='Case B',1,0) as "Case B",if(FirstCase='Case D',1,0) as "Case D" 
resident FirstSortedValue;

drop table FirstSortedValue;

 

 

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

View solution in original post

Taoufiq_Zarra

Hi Priya,

try to change Sum([Case A]+Sum([Case B]+Sum([Case D]

by :

=sum( aggr(only([Case D]),Reason))+sum( aggr(only([Case B]),Reason))+sum( aggr(only([Case A]),Reason))

 

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

View solution in original post

5 Replies
Taoufiq_Zarra

 

Data :

LOAD rowno() as IDcase,trim(subfield(Reason,';')) as Cases,* INLINE [
    Case,Reason
    1, Case A; Case B
    2, Case B
    3, Case C; Case A
    4, Case D; Case B
    5, Case A; Case C
    6, Case B;Case D
    7, Case E
];

FirstSortedValue:
noconcatenate
LOAD Case,FirstSortedValue(Cases, IDcase) as FirstCase Resident Data  where match(Cases,'Case A','Case B','Case D')>0 Group By Case ;
left join load * resident Data;

drop table Data;

output:
noconcatenate
load Case,Reason,if(FirstCase='Case A',1,0) as "Case A",if(FirstCase='Case B',1,0) as "Case B",if(FirstCase='Case D',1,0) as "Case D" 
resident FirstSortedValue;

drop table FirstSortedValue;

 

 

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") 😉
priya945
Creator
Creator
Author

😂Kudos  and thank you Taoufiq. your logic works

priya945
Creator
Creator
Author

Hi Taoufiq,

Could you please  do favor for below logic.  How to get sum of only listed cases(Case A, Case B, Case D)

Expected o/p is below 

 Sum([Case A]+Sum([Case B]+Sum([Case D]
Case A3
Case B2
Case D1

 

From

ReasonCase ACase BCase D
Case A; Case B100
Case A; Case C100
Case B010
Case B;Case D010
Case C; Case A100
Case D; Case B001
 321

Thanks In advance.

Taoufiq_Zarra

Hi Priya,

try to change Sum([Case A]+Sum([Case B]+Sum([Case D]

by :

=sum( aggr(only([Case D]),Reason))+sum( aggr(only([Case B]),Reason))+sum( aggr(only([Case A]),Reason))

 

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") 😉
priya945
Creator
Creator
Author

Thank You once again Taoufiq 😊