3 Replies Latest reply: Aug 19, 2014 4:37 AM by Marco Wedel RSS

    Bitwise / bitflag / flag column data

    Sebastian Öhman

      Hello!

       

      I have data which I have a problem understanding how to import/visualize in QlikView.

      It follows: Bitwise operation - Wikipedia, the free encyclopedia

       

      Colors:

      LOAD * INLINE [

          ColorName, CarColor

          Red, 1

          Yellow, 2

          Green, 4

          Blue, 8

          Orange, 16

      ];

       

      Cars:

      LOAD * INLINE [

          CarName, CarColor

          A, 1

          B, 2

          C, 4

          D, 8

          E, 16

          F, 3

          G, 12

          H, 7

      ];

       

      I have two different usages and expected results:

       

      CaseA (all is required):

      Red -> A

      Yellow -> B

      Red+Yellow  -> (1+2  = 3) -> F 

      Red+Yellow+Green - > (1+2+4 = 7) -> H

       

      Case B (any required)

      Red (1) -> A  +  F (1 + 2) + H (1 + 2+ 4)

      Red+Yellow  ->  F(1 + 2)   +H  (1+2+4)

       

      This is clearly not working right out of the box since Qlik matches the integers as they are, and not as the calculations I want done.

      How do I solve this?

       

      /Sebastian

        • Re: Bitwise / bitflag / flag column data
          Marco Wedel

          Hi Sebastian,

           

          one solution for at least parts of your requirements:

           

          Colors:
          LOAD * INLINE [
              ColorName, CarColor
              Red, 1
              Yellow, 2
              Green, 4
              Blue, 8
              Orange, 16
          ];
          
          Cars:
          LOAD *
          Where CarColor;
          LOAD *,
              CarColors bitand pow(2, IterNo()-1) as CarColor
          While IterNo() <= Floor(log(CarColors)/log(2))+1;
          LOAD * INLINE [
              CarName, CarColors
              A, 1
              B, 2
              C, 4
              D, 8
              E, 16
              F, 3
              G, 12
              H, 7
          ];
          
          
          

           

          QlikCommunity_Thread_129689_Pic3.JPG.jpg

          QlikCommunity_Thread_129689_Pic2.JPG.jpg

           

          QlikCommunity_Thread_129689_Pic1.JPG.jpg

           

          hope this helps

           

          regards

           

          Marco