Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

gopikrishnach
Contributor

Case statement Replacement

Hi, In my application so many CASE statements have been used to extract the data from database at script level. But today I got requirement that need to replace CASE statements with qlik functions. But I am not able to find that. Could you please some one help me?

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

case when (((Eleven_Tables44.COMP_NUMBER = 1) and (Eleven_Tables44.RESULT_TYPE = 'T3')) or ((Eleven_Tables44.UNIT_NUMBER = 1) and (Eleven_Tables44.RESULT_TYPE = 'T4'))) then Eleven_Tables44.PRIMARY_LIMITS else '' end  as  PRIMARY_LIMITS

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I tried with If Condition, but the data is not coming correctly.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

IF(((COMP_NUMBER=1 AND RESULT_TYPE='T3') OR (UNIT_NUMBER=1 AND RESULT_TYPE='T4')),PRIMARY_LIMITS,'') AS PRIMARY_LIMITS_1

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thank you.

5 Replies
dapostolopoylos
Contributor III

Re: Case statement Replacement

The transalation of SQL to Qlik script you did is correct, i wouldn't do it in a different way...

Is it possible that your data when they are downloaded to Qlik are somehow affected in a way?

Father/Husband/BI Developer
vasiliy_beshent
Contributor III

Re: Case statement Replacement

try this

if((Eleven_Tables44.COMP_NUMBER = 1 and Eleven_Tables44.RESULT_TYPE = 'T3')

or (Eleven_Tables44.UNIT_NUMBER = 1 and Eleven_Tables44.RESULT_TYPE = 'T4'), Eleven_Tables44.PRIMARY_LIMITS, '')

vikasmahajan
Honored Contributor III

Re: Case statement Replacement

you can use pick match like following syntax

pick(match("COMPANY_NAME",'A','B','C',"COMPANY_NAME"),'COMP A','COMP B','COMP C') as COMP,

Vikas

gopikrishnach
Contributor

Re: Case statement Replacement

Hi Vasiliy, I tried your code, but it is not working. Still the data is not matching. Thank you.

gopikrishnach
Contributor

Re: Case statement Replacement

Hi Vikas, Can you please elaborate, How will use pick match here.