1 Reply Latest reply: Oct 17, 2017 3:57 AM by Jonathan Dienst RSS

    convert case statement in qliksense

    Ajinkya Bhonsle,

      Hi All,

       

      I have a case statement which I need to convert it to Qlik Script.

       

                      case  when
          ServiceChartField  = '0000'
                                                      then
                                                                      case 
                                                                                      when Model             like '%Accessories%'     then 'Accessories'
                                                                                      when Model              like '%Licenses%'           then 'Licenses'
                                                                                      when SubModel      like '%Software%'          then 'Software'
                                                                      else
                                                                                      'System'
                                                                      end 
                                                      else 'Service'
                      end

       

      Can you guys help me in writing the script.

       

      So far I have got this, not sure if its correct:

      if(wildmatch([Model], '*Accessories*' ),'Accessories',

          if(wildmatch([Model], '*Licenses*' ), 'Licenses',

          if(wildmatch([SubModel], '*Software*') ,'Software' ,

          if(wildmatch([SubModel], '*System*') ,'System' ,

          if(wildmatch([SubModel], '*Service*') ,'Service' ,)

        

          ))))

        • Re: convert case statement in qliksense
          Jonathan Dienst

          I think this an accurate conversion of the CASE statement:

           

          If(ServiceChartField = '0000',

            If(Model like '*Accessories*', 'Accessories',

            If(Model like '*Licenses*', 'Licenses',

            If(SubModel like '*Software*', 'Software',

            'System'))),

            'Service'

          )


          I prefer Like to WildMatch for a single comparison as it makes for more readable code