6 Replies Latest reply: Dec 15, 2017 11:33 AM by Sunny Talwar RSS

    Many if's

    Gleybson Fernandes

      Hello people,

      I need to create an index from a text field.

      so I started doing it like this:

      if (index (upper ("Text Neg"), 'GIN'), 'Drink'

      if (index (upper ("Text Neg"), 'VODKA'), 'Drink'

      if (index (upper ("Text Neg"), 'VODCA'), 'Drink', ...

      The problem is that there are a lot of words and when it arrives in about 50 ifs it catches.

      I'm using QlikSense nov2017.

      Do you have any other solution for me not to use all these if's?

        • Re: Many if's
          Sunny Talwar

          May be with Pick(WildMatch())

           

          Pick(WildMatch([Text Neg], '*GIN*', '*VODKA*', '*VODCA*', ...), 'Drink', 'Drink', 'Drink', ....) ....

            • Re: Many if's
              Gleybson Fernandes

              I applied that way.

              I think I made a mistake.

               

              Pick(

                  WildMatch("Text Neg",

                      '*GIN*', '*VODKA*', '*VODCA*', 'Drink', 'Drink', 'Drink')) as Indice,

                • Re: Many if's
                  Sunny Talwar

                  I think you misplaced on parenthesis

                   

                  Pick(

                      WildMatch("Text Neg",

                          '*GIN*', '*VODKA*', '*VODCA*'), 'Drink', 'Drink', 'Drink') as Indice,

                    • Re: Many if's
                      Sunny Talwar

                      I see that I missed that in my response also.... fixed my response also

                        • Re: Many if's
                          Gleybson Fernandes

                          Perfect friend.

                          It worked. Just one more thing.

                          for every word I put in "WildMatch" do I have to repaint it in "Pick"?

                           

                           

                          Example below.

                           

                          Pick(

                              WildMatch("Text Neg",

                                  'GIN',         'VODKA',         'VODCA',        'VÓDCA',        'VÓDKA',

                                  'VODIKA',      'VÓDICA',        'VÓDIKA',       'GIM',        'CONHAQUE',

                                  'COMIDA',        'BOLO',        'BOLINHO',        'COMIDA DE PRIMEIRA'

                                 

                                  ), 'Drink', 'Drink', 'Drink', 'Drink', 'Drink', 'Drink', 'Drink', 'Drink', 'Drink', 'Drink',

                                  'Comida', 'Comida', 'Comida', 'Comida') as Indice,

                            • Re: Many if's
                              Sunny Talwar

                              Yes, or you can do something like this

                               

                              If(WildMatch("Text Neg",

                                      'GIN',        'VODKA',        'VODCA',        'VÓDCA',        'VÓDKA',

                                      'VODIKA',      'VÓDICA',        'VÓDIKA',      'GIM',        'CONHAQUE'), 'Drink', 'Comida') as Indice

                               

                              or this

                              If(WildMatch("Text Neg",

                                      'GIN',        'VODKA',        'VODCA',        'VÓDCA',        'VÓDKA',

                                      'VODIKA',      'VÓDICA',        'VÓDIKA',      'GIM',        'CONHAQUE'), 'Drink',

                              If(WildMatch("Text Neg",

                                      'COMIDA',        'BOLO',        'BOLINHO',        'COMIDA DE PRIMEIRA'),

                              'Comida') as Indice

                               

                              But if you do use Pick, then you will have to repeat Drink for all the matches you make