<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Setting field to a variable in load script in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Setting-field-to-a-variable-in-load-script/m-p/1581689#M42498</link>
    <description>&lt;P&gt;Hi Ben,&lt;/P&gt;&lt;P&gt;You could make the user select both cities, by doind two separate data sets of the spreadsheet you have and make them qualified, so they are separate from one another.&lt;/P&gt;&lt;P&gt;After that, you can get the selection of both fields to fill in your expression dinamycally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So let's say I have this as city "points" for lat and longs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Qualify *;&lt;BR /&gt;Selection_1:&lt;BR /&gt;load * Inline&lt;BR /&gt;[&lt;BR /&gt;City,_Lat,_Long&lt;BR /&gt;ABC,1,2&lt;BR /&gt;ABD,10,5&lt;BR /&gt;ACD,200,100,&lt;BR /&gt;X,25.7617,-80.1918&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;Selection_2:&lt;BR /&gt;load * Inline&lt;BR /&gt;[&lt;BR /&gt;City,_Lat,_Long&lt;BR /&gt;ABC,1,2&lt;BR /&gt;ABD,10,5&lt;BR /&gt;ACD,200,100,&lt;BR /&gt;X,25.7617,-80.1918&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll have two data sets for every city, so I can select two and make the calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create 4&amp;nbsp; variables for each long / lat, like so:&lt;/P&gt;&lt;P&gt;Lat1&lt;/P&gt;&lt;P&gt;=only([Selection_1._Lat])&lt;/P&gt;&lt;P&gt;Lat2&lt;/P&gt;&lt;P&gt;=only([Selection_2._Lat])&lt;/P&gt;&lt;P&gt;Long1&lt;/P&gt;&lt;P&gt;=only([Selection_1._Long])&lt;/P&gt;&lt;P&gt;Long2&lt;/P&gt;&lt;P&gt;=only([Selection_2._Long])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With that, you'll be able to select on the app which cities you want.&lt;/P&gt;&lt;P&gt;Create another variable, with the function you have:&lt;/P&gt;&lt;P&gt;Function&lt;/P&gt;&lt;P&gt;num&lt;BR /&gt;(&lt;BR /&gt;(&lt;BR /&gt;(&lt;BR /&gt;(2 *&lt;BR /&gt;(atan2(&lt;BR /&gt;sqrt((sqr(sin((($(Lat1) * Pi() / 180) - ($(Lat2) * Pi() / 180)) / 2))&lt;BR /&gt;+&lt;BR /&gt;(&lt;BR /&gt;(cos(($(Lat2) * Pi() / 180)) * cos(($(Lat1) * Pi() / 180)))&lt;BR /&gt;* sqr(sin((($(Long1) * Pi() / 180) - ($(Long2) * Pi() / 180)) / 2))&lt;BR /&gt;)&lt;BR /&gt;)),&lt;BR /&gt;sqrt((1-(&lt;BR /&gt;sqr(sin((($(Lat1) * Pi() / 180) - ($(Lat2) * Pi() / 180)) / 2))&lt;BR /&gt;+ ((cos(($(Lat2) * Pi() / 180)) * cos(($(Lat1) * Pi() / 180)))&lt;BR /&gt;* sqr(sin((($(Long1) * Pi() / 180) - ($(Long2) * Pi() / 180)) / 2))&lt;BR /&gt;)&lt;BR /&gt;))&lt;BR /&gt;)))) * 6371) * 0.621371),'#,##0') as Miles&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And apply as expression the $(Function) (that will expand the expression and the variables within.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Felipe.&lt;/P&gt;</description>
    <pubDate>Fri, 17 May 2019 18:20:57 GMT</pubDate>
    <dc:creator>felipedl</dc:creator>
    <dc:date>2019-05-17T18:20:57Z</dc:date>
    <item>
      <title>Setting field to a variable in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-field-to-a-variable-in-load-script/m-p/1581674#M42495</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to grab people within a certain distance from a specified city. Right now, I set the coordinates for the city in the load script, and call it later in the haversine formula (which works). I would prefer to allow the front end user to choose the city dynamically so I don't have to reload the app every time they want to choose a new city. Here is my current script, along with an example city (set variable). The "Zip" maps to a user DB, and brings along all of their information.&lt;/P&gt;&lt;P&gt;//Miami&lt;BR /&gt;LET Lat2 = 25.7617;&lt;BR /&gt;LET Long2 = -80.1918;&lt;/P&gt;&lt;P&gt;//==========================================&lt;BR /&gt;//Load USCities3 from Attached files&amp;nbsp;&lt;BR /&gt;//==========================================&lt;/P&gt;&lt;P&gt;LOAD&lt;BR /&gt;City2,&lt;BR /&gt;Zipcode2 as Zip,&lt;BR /&gt;Lat3,&lt;BR /&gt;Long3,&lt;BR /&gt;GeoMakePoint(Lat3,Long3) as Location,&lt;BR /&gt;&lt;BR /&gt;num((((2 *&lt;BR /&gt;(atan2(&lt;BR /&gt;sqrt((sqr(sin((($(Lat2) * Pi() / 180) - (Lat3 * Pi() / 180)) / 2))&lt;BR /&gt;+ ((cos((Lat3 * Pi() / 180)) * cos(($(Lat2) * Pi() / 180)))&lt;BR /&gt;* sqr(sin((($(Long2) * Pi() / 180) - (Long3 * Pi() / 180)) / 2))&lt;BR /&gt;)&lt;BR /&gt;)),&lt;BR /&gt;sqrt((1-(&lt;BR /&gt;sqr(sin((($(Lat2) * Pi() / 180) - (Lat3 * Pi() / 180)) / 2))&lt;BR /&gt;+ ((cos((Lat3 * Pi() / 180)) * cos(($(Lat2) * Pi() / 180)))&lt;BR /&gt;* sqr(sin((($(Long2) * Pi() / 180) - (Long3 * Pi() / 180)) / 2))&lt;BR /&gt;)&lt;BR /&gt;))&lt;BR /&gt;)))) * 6371) * 0.621371),'#,##0') as Miles&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;FROM [lib://AttachedFiles/USCities3.xlsx]&lt;BR /&gt;(ooxml, embedded labels, table is Sheet1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried bringing in a duplicate table (USCities3) and renaming the fields so they won't associate with the other table (and left out the haversine). I concatenated them, and did a resident load since lat2/long2 wouldn't be found otherwise. The "city" fields still query each other, so I get no output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help with this.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ben&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 17:15:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-field-to-a-variable-in-load-script/m-p/1581674#M42495</guid>
      <dc:creator>BPetosa</dc:creator>
      <dc:date>2019-05-17T17:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Setting field to a variable in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-field-to-a-variable-in-load-script/m-p/1581689#M42498</link>
      <description>&lt;P&gt;Hi Ben,&lt;/P&gt;&lt;P&gt;You could make the user select both cities, by doind two separate data sets of the spreadsheet you have and make them qualified, so they are separate from one another.&lt;/P&gt;&lt;P&gt;After that, you can get the selection of both fields to fill in your expression dinamycally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So let's say I have this as city "points" for lat and longs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Qualify *;&lt;BR /&gt;Selection_1:&lt;BR /&gt;load * Inline&lt;BR /&gt;[&lt;BR /&gt;City,_Lat,_Long&lt;BR /&gt;ABC,1,2&lt;BR /&gt;ABD,10,5&lt;BR /&gt;ACD,200,100,&lt;BR /&gt;X,25.7617,-80.1918&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;Selection_2:&lt;BR /&gt;load * Inline&lt;BR /&gt;[&lt;BR /&gt;City,_Lat,_Long&lt;BR /&gt;ABC,1,2&lt;BR /&gt;ABD,10,5&lt;BR /&gt;ACD,200,100,&lt;BR /&gt;X,25.7617,-80.1918&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll have two data sets for every city, so I can select two and make the calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create 4&amp;nbsp; variables for each long / lat, like so:&lt;/P&gt;&lt;P&gt;Lat1&lt;/P&gt;&lt;P&gt;=only([Selection_1._Lat])&lt;/P&gt;&lt;P&gt;Lat2&lt;/P&gt;&lt;P&gt;=only([Selection_2._Lat])&lt;/P&gt;&lt;P&gt;Long1&lt;/P&gt;&lt;P&gt;=only([Selection_1._Long])&lt;/P&gt;&lt;P&gt;Long2&lt;/P&gt;&lt;P&gt;=only([Selection_2._Long])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With that, you'll be able to select on the app which cities you want.&lt;/P&gt;&lt;P&gt;Create another variable, with the function you have:&lt;/P&gt;&lt;P&gt;Function&lt;/P&gt;&lt;P&gt;num&lt;BR /&gt;(&lt;BR /&gt;(&lt;BR /&gt;(&lt;BR /&gt;(2 *&lt;BR /&gt;(atan2(&lt;BR /&gt;sqrt((sqr(sin((($(Lat1) * Pi() / 180) - ($(Lat2) * Pi() / 180)) / 2))&lt;BR /&gt;+&lt;BR /&gt;(&lt;BR /&gt;(cos(($(Lat2) * Pi() / 180)) * cos(($(Lat1) * Pi() / 180)))&lt;BR /&gt;* sqr(sin((($(Long1) * Pi() / 180) - ($(Long2) * Pi() / 180)) / 2))&lt;BR /&gt;)&lt;BR /&gt;)),&lt;BR /&gt;sqrt((1-(&lt;BR /&gt;sqr(sin((($(Lat1) * Pi() / 180) - ($(Lat2) * Pi() / 180)) / 2))&lt;BR /&gt;+ ((cos(($(Lat2) * Pi() / 180)) * cos(($(Lat1) * Pi() / 180)))&lt;BR /&gt;* sqr(sin((($(Long1) * Pi() / 180) - ($(Long2) * Pi() / 180)) / 2))&lt;BR /&gt;)&lt;BR /&gt;))&lt;BR /&gt;)))) * 6371) * 0.621371),'#,##0') as Miles&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And apply as expression the $(Function) (that will expand the expression and the variables within.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Felipe.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 18:20:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-field-to-a-variable-in-load-script/m-p/1581689#M42498</guid>
      <dc:creator>felipedl</dc:creator>
      <dc:date>2019-05-17T18:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Setting field to a variable in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-field-to-a-variable-in-load-script/m-p/1582987#M42616</link>
      <description>&lt;P&gt;Hi Felipe,&lt;/P&gt;&lt;P&gt;Sorry for the delay, I have been out of town. This got me really close to where I want to be. I think I can figure it out for here, but may comment again. This is really good stuff, and I have some other use cases for it.&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;Ben&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 20:42:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-field-to-a-variable-in-load-script/m-p/1582987#M42616</guid>
      <dc:creator>BPetosa</dc:creator>
      <dc:date>2019-05-21T20:42:30Z</dc:date>
    </item>
  </channel>
</rss>

