6 Replies Latest reply: May 12, 2012 6:53 AM by welsa_chy RSS

    Creating tables within a loop

      Hi.. I am new to qlikview..


      I am trying to create tables within a loop and here is the code:..


      i have a table Categories(CategoryID,CategoryName) and a table Products(ProductID,ProductName,CategoryID) which explains why i am joining the two tables to retrieve each product and their category.


      Then i want to create a table for each category and input the product names beloging to that category in the corresponding tables.


      SET vCategory=' ' ;



      mapping LOAD ProductName as PN,CategoryID

      resident Products;


      LOAD CategoryID

      RESIDENT Categories where exists(CategoryID);


      For i=0 to NoOfRows('Categories')

           vCategory = Peek('CategoryID',$(i),Categories);


           For j=0 to NoOfRows('Products')-1



                APPLYMAP('catname',CategoryID) as ProductName;

           Next j;

      Next i;


      I just cannot understand what is wrong with that...i tried for a whole day.. please if you can help me out

        • Creating tables within a loop
          Jagan Nalla



          I don't know what you want exactly. But when i look through your script you are using wrong way of mapping concept. Through mapping concept we should match key values perfectly. For example,



          mapping load * inline [

          x, y

          1, one

          2, two

          3, three ] ;


          ApplyMap ('map1', 2 ) returns ' two'

          ApplyMap ('map1', 4 ) returns 4

          ApplyMap ('map1', 5, 'xxx') returns 'xxx'

          ApplyMap ('map1', 1, 'xxx') returns 'one'

          ApplyMap ('map1', 5, null( ) ) returns NULL

          ApplyMap ('map1', 3, null( ) ) returns 'three'