Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
karthik_nataraj
Contributor II
Contributor II

Row selection in if statement

Hi All, 

I need to create an if statement in pivot table for the below condition, can anyone help me on this?

If(Operation_status='Planned', then I need only first row from planned table)

Input Output required
operation_status    
plannedCricket PlannedCricket
 Football   
 Throwball   
 Swimming   
 Cycling   
     
ActiveFootball ActiveFootball
 Throwball   
 Swimming   
 Cycling   

 

Labels (1)
5 Replies
Taoufiq_Zarra

@karthik_nataraj  can you share the Input Table ? is it two column ?

 

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉
karthik_nataraj
Contributor II
Contributor II
Author

Hi,

Thanks for your reply, Please find the below input table fyr.

Input
operation_statusoperation_description
plannedCricket
 Football
 Throwball
 Swimming
 Cycling
  
ActiveFootball
 Throwball
 Swimming
 Cycling

 

if operation_status is planned then by default my operation_description should be first row(i.e. cricket)  

Taoufiq_Zarra

@karthik_nataraj  The input like this ?

Taoufiq_Zarra_0-1606123989387.png

 

and if operation_status is  Active return all value ?

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉
karthik_nataraj
Contributor II
Contributor II
Author

Yes input is as shown above

 

Taoufiq_Zarra

@karthik_nataraj  you can for example (If I understood correctly) :

Data:

LOAD *,if(rowno()=1,1,if(peek(operation_status)=operation_status,peek(IDtmp)+1,1)) as IDtmp,rowno() as IDRank INLINE [
    operation_status, operation_description
    planned, Cricket
    planned, Football
    planned, Throwball
    planned, Swimming
    planned, Cycling
    Active, Football
    Active, Throwball
    Active, Swimming
    Active, Cycling
];


output:
noconcatenate

load * resident Data where operation_status='planned' and IDtmp=1;
load * resident Data where Match(operation_status,'planned')=0;

drop table Data;
drop fields IDtmp,IDRank;

output:

Capture.PNG

this approch allow you also if you have more than one planned like :

Data:

LOAD *,if(rowno()=1,1,if(peek(operation_status)=operation_status,peek(IDtmp)+1,1)) as IDtmp,rowno() as IDRank INLINE [
    operation_status, operation_description
    planned, Cricket
    planned, Football
    planned, Throwball
    planned, Swimming
    planned, Cycling
    Active, Football
    Active, Throwball
    Active, Swimming
    Active, Cycling
    planned, Football
    planned, Throwball
    planned, Swimming
    planned, Cycling
];


output:
noconcatenate

load * resident Data where operation_status='planned' and IDtmp=1;
load * resident Data where Match(operation_status,'planned')=0;

drop table Data;
drop fields IDtmp;

 

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