12 Replies Latest reply: Aug 4, 2016 4:56 PM by Youness Ghanim RSS

    "Load" within a for loop with passing dynamic values!

    Youness Ghanim

      Greetings,

       

      I am experimenting with a weather app and I am trying to pull data for the cities present in my excel file, I am trying something like this:

       

      // Load relatives and friends locations
      Relatives:
      LOAD
      "Family member" as Name,
      Relation,
      City
      FROM [C:\Users\YHA\Desktop\WeatherApp\data\Relatives.xlsx]
      (
      ooxml, embedded labels, table is Sheet1);

      // Load weather data per city
      let vCity = '';
      let noRows = NoOfRows('Relatives')-1;
      for i=0 to $(noRows)
          let vCity=FieldValue('City',$(i));
          LOAD

              $(vCity) as City,
      [humidity/value] as humidity,
      [temperature/min] as min,
      [temperature/max] as max
      [location/country] as country
      From
      [http://api.openweathermap.org/data/2.5/forecast/daily?q='$(vCity)';&mode=xml&units=metric&cnt=1&appid=9d74c2cc68eee64f9109f7e9a6404a1a]
      Resident Relatives;
      next i

       

      The above code doesn’t compile and may sound primitive, but it gives an idea of what I am trying to achieve. I included my private weather API key in case someone wants to test with actual data.

       

      Note that nesting a load statement inside a for loop in Qlik Sense doesn’t work for some reasons!

       

      What I am trying to achieve is map weather data using city as a key to my friends and relatives data set so that I get weather data per city. Not sure if that is clear!

       

      Regards