4 Replies Latest reply: Sep 26, 2014 7:23 PM by Marco Wedel RSS

    how to write apply map to two Flags


      Hi Friends,

       

      I have data like this

      A B C D Amount

      1 2 3 4   100

      2 3 4 5 900

      5 6 7 8 900

      Now based on the fieds A B and C I need to decide the amount type.

       

      I have combinations for A and B for one and A,B and C for another amount type.

       

      Can I include two apply map conditions in the same code???

       

      Thanks

      Pavan

        • Re: how to write apply map to two Flags
          Friedrich Hofmann

          Hi pavan,

           

          no, an ApplyMap() can only involve one field - but you can comine two fields into a compound and then check that against your mapping table?

          HTH

           

          Best regards,

           

          DataNibbler

          • Re: how to write apply map to two Flags
            Malek Safa

            mapping table only takes 2 columns, the source and destination (mapped) column, so if your key is A, B, C, D, you should create a combined key of ABCD as SourceColumn and Amount as Destination and then you will map on SourceColumn.

            • Re: how to write apply map to two Flags
              Marco Wedel

              Hi,

               

              maybe this helps?:

               

              QlikCommunity_Thread_135188_Pic1.JPG.jpg

               

              tabABCmap:
              LOAD * Inline [
              A,B,C, amount type
              1,1,1,type1
              1,1,2,type2
              1,1,3,type3
              1,2,1,type4
              1,2,2,type5
              1,2,3,type6
              2,1,1,type7
              2,1,2,type8
              2,1,3,type9
              2,2,1,type10
              2,2,2,type11
              2,2,3,type12
              1,3,,type13
              2,3,,type14
              3,1,,type15
              3,2,,type16
              3,3,,type17
              ];
              
              mapABC:
              Mapping LOAD
                AutoNumberHash128(A,B,C),
                [amount type]
              Resident tabABCmap;
              
              DROP Table tabABCmap;
              
              tabData:
              LOAD *,
                  ApplyMap('mapABC', AutoNumberHash128(A,B,If(A>2 or B>2,'',C))) as [amount type];
              LOAD Ceil(Rand()*3) as A,
                  Ceil(Rand()*3) as B,
                  Ceil(Rand()*3) as C,
                  Ceil(Rand()*1000) as Amount
              AutoGenerate 50;
              

               

              regards

               

              Marco

                • Re: Re: how to write apply map to two Flags
                  Marco Wedel

                  on the other hand, maybe you meant

                   

                  QlikCommunity_Thread_135188_Pic1.JPG.jpg

                   

                  tabABCmap:
                  LOAD * Inline [
                  A,B,C, amount type
                  1,1,1,type1
                  1,1,2,type2
                  1,1,3,type3
                  1,2,1,type4
                  1,2,2,type5
                  1,2,3,type6
                  2,1,1,type7
                  2,1,2,type8
                  2,1,3,type9
                  2,2,1,type10
                  2,2,2,type11
                  2,2,3,type12
                  1,3,,type13
                  2,3,,type14
                  3,1,,type15
                  3,2,,type16
                  3,3,,type17
                  ];
                  
                  mapABC:
                  Mapping LOAD
                    AutoNumberHash128(A,B,C),
                    [amount type]
                  Resident tabABCmap
                  Where C<>'';
                  
                  mapAB:
                  Mapping LOAD
                    AutoNumberHash128(A,B),
                    [amount type]
                  Resident tabABCmap
                  Where C='';
                  
                  DROP Table tabABCmap;
                  
                  tabData:
                  LOAD *,
                      If(not IsNum(ApplyMap('mapABC', AutoNumberHash128(A,B,C))), ApplyMap('mapABC', AutoNumberHash128(A,B,C))) as [amount type],
                      If(not IsNum(ApplyMap('mapAB', AutoNumberHash128(A,B))), ApplyMap('mapAB', AutoNumberHash128(A,B))) as [amount type 2];
                  LOAD Ceil(Rand()*3) as A,
                      Ceil(Rand()*3) as B,
                      Ceil(Rand()*3) as C,
                      Ceil(Rand()*1000) as Amount
                  AutoGenerate 50;
                  

                   

                  hope this helps

                   

                  regards

                   

                  Marco