1 Reply Latest reply: Jul 30, 2015 11:56 AM by Simon Hogg RSS

    Can a script be looped to reload data with different variables?

    Simon Hogg
      1. I have a load script to load data from SAP BW.  It uses lots of long, technical names and is user-unfriendly.
      2. SAP BW also has a limit on how much data is returned from a query. My query will not give me all the data I want all at once.

       

      Currently I have multiple copies of my SAP BW query, at the moment splitting my data into annual chunks.  I load 2010 from the 2010 query, then 2011, then 2012, etc. and Qlik Sense joins it all together neatly.

       

      I am now looking at streamlining the process to avoid duplication of BW queries and am using WHERE {[0CALYEAR].[2010]} to load the data one year at a time, but I still have multiple copies of the MDX query in my Qlik Sense script.

       

      Since the MDX doesn't change (apart from the year), is it possible to;

      • assign a variable
      • run the load script
      • increment the variable
      • then re-run the load script with a loop?

       

      Thanks for any pointers.

        • Re: Can a script be looped to reload data with different variables?
          Simon Hogg

          Oh yes, it is!!!

           

          For vYear = 2010 to 2015                                  //defines loop variable

                    Load

                        <Insert Load Script here, with definitions & MDX/query>

                    WHERE {[0CALYEAR].[$(vYear)]};          // This is where my variable is used

          Next vYear                                                        // Loops round