6 Replies Latest reply: Apr 11, 2016 7:19 PM by Stefan Wühl RSS

    Loop Script help


      I am quite new in development in QlikView scripting and I would like to ask for help.


      My original data consist of 3 columns: Date, Part_old and Part_new. When there is just one change there is no problem for me to write script. Problem is when, like you see in example a part  'aaaa' is replaced  by 'bbbb' on January 1st and afterwards the part 'bbbb' to 'eeee'. Below you can see the original data structure and  the desired new layout.


      I thought about do while statement, but I am not able to declare variable which will take the value from column C, check the whole column B to find whether there is more replacements of part and write it in a way I described above.



      Thanks for help


        • Re: Loop Script help
          Sunny Talwar

          I don't really understand what you are trying to do here. Can you may be elaborate a little more?

          • Re: Loop Script help
            Stefan Wühl

            Shouldn't the third line / 'Partold_original' value  be 'cccc'?

            • Re: Loop Script help

              Yes swuehl, you are right. It is 'cccc'


              The idea is that original table is sorted by date in ascending order (older to younger) when Part_old was subsituted by Part_new, but there can  be 1 to n substitutes.  I would like to see those substitutes line by line. It means that part_new can be in another line shown like part_old substituted by another part. The aim is to create script to check it and organize it in a way shown above.


              Column D will just show the first original part and doesn't take into consideration no of substitutes.

                • Re: Loop Script help
                  Stefan Wühl

                  Here is another idea. Not really sure if this is applicable to your setting, let's see:


                  Hierarchy (Part_new,Part_old, NodeName,ParentName,NodeName,Path,'/',Depth)
                  LOAD *,  Part_new as NodeName, RowNo() as RowID;
                  LOAD Date, RecID, If(IterNo()=2,Null(),Part_old) as Part_old, If (IterNo()=2,Part_old,Part_new) as Part_new
                  While iterno() <= Num;
                  LOAD *, Recno() as RecID, If(not Exists(Part_new,Part_old),2,1) as Num INLINE [
                  Date, Part_old, Part_new
                  LOAD *, Subfield(Path,'/',1) as Part_old_orig
                  Resident Hierarchy
                  WHERE Len(trim(Part_old));
                  DROP TABLE Hierarchy;


                  Date Part_old Part_new Part_old_orig Path
                • Re: Loop Script help

                  Great!! Thank you very much.


                  Just  noticed one problem. I try to apply order by statement but without success because sometimes the path is going form older date to younger, sometimes vice versa, any suggestions to which line apply the condition??