<?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 Haversine formula to find distance between two lat/long points in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234630#M86017</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured I would take a moment to share a code snippet that uses the Haversine formula to calculate the distance between two lat/long points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;&lt;BR /&gt;// use the 'haversine' formula to calculate distance between two lat/long points for each record&lt;BR /&gt;// The Haversine formula can be broken into multiple pieces or steps - I chose to do the entire formula&lt;BR /&gt;// in one step. This makes it more difficult to read/understand, but allows QlikView to do it all at once&lt;BR /&gt;// when reading a record. If I broke it up, then QlikView would have to examine each record for each step of the&lt;BR /&gt;// process increasing time and decreasing efficiency.&lt;BR /&gt;// formula notes:&lt;BR /&gt;// &lt;A href="http://www.movable-type.co.uk/scripts/latlong.html"&gt;http://www.movable-type.co.uk/scripts/latlong.html&lt;/A&gt;&lt;BR /&gt;// convert degrees to radians: rads=degrees*pie / 180&lt;BR /&gt;// radius of earth = 6371km (constant)&lt;BR /&gt;&lt;BR /&gt;CalcDistances:&lt;BR /&gt;noconcatenate&lt;BR /&gt;load&lt;BR /&gt; zipcode,&lt;BR /&gt; state,&lt;BR /&gt; country,&lt;BR /&gt; Latitude1,&lt;BR /&gt; Longitude1,&lt;BR /&gt; weatherStationID,&lt;BR /&gt; Latitude2,&lt;BR /&gt; Longitude2,&lt;BR /&gt; // the Haversine formula&lt;BR /&gt; (2 *&lt;BR /&gt; (atan2(&lt;BR /&gt; sqrt((sqr(sin(((Latitude2 * Pi() / 180) - (Latitude1 * Pi() / 180)) / 2))&lt;BR /&gt; + ((cos((Latitude1 * Pi() / 180)) * cos((Latitude2 * Pi() / 180)))&lt;BR /&gt; * sqr(sin(((Longitude2 * Pi() / 180) - (Longitude1 * Pi() / 180)) / 2))&lt;BR /&gt; )&lt;BR /&gt; )),&lt;BR /&gt; sqrt((1-(&lt;BR /&gt; sqr(sin(((Latitude2 * Pi() / 180) - (Latitude1 * Pi() / 180)) / 2))&lt;BR /&gt; + ((cos((Latitude1 * Pi() / 180)) * cos((Latitude2 * Pi() / 180)))&lt;BR /&gt; * sqr(sin(((Longitude2 * Pi() / 180) - (Longitude1 * Pi() / 180)) / 2))&lt;BR /&gt; )&lt;BR /&gt; ))&lt;BR /&gt; )))) * 6371 as Distance_km&lt;BR /&gt;resident AllPossibleZipWeatherStationCombinations;&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;Example of input/output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="error loading image" class="jive-image error-loading-image" src="https://community.qlik.com/legacyfs/online/-4196_sourceID:4196" /&gt;&lt;/P&gt;&lt;P&gt;- Trevor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Apr 2011 18:30:23 GMT</pubDate>
    <dc:creator>rothtd</dc:creator>
    <dc:date>2011-04-28T18:30:23Z</dc:date>
    <item>
      <title>Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234630#M86017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured I would take a moment to share a code snippet that uses the Haversine formula to calculate the distance between two lat/long points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;&lt;BR /&gt;// use the 'haversine' formula to calculate distance between two lat/long points for each record&lt;BR /&gt;// The Haversine formula can be broken into multiple pieces or steps - I chose to do the entire formula&lt;BR /&gt;// in one step. This makes it more difficult to read/understand, but allows QlikView to do it all at once&lt;BR /&gt;// when reading a record. If I broke it up, then QlikView would have to examine each record for each step of the&lt;BR /&gt;// process increasing time and decreasing efficiency.&lt;BR /&gt;// formula notes:&lt;BR /&gt;// &lt;A href="http://www.movable-type.co.uk/scripts/latlong.html"&gt;http://www.movable-type.co.uk/scripts/latlong.html&lt;/A&gt;&lt;BR /&gt;// convert degrees to radians: rads=degrees*pie / 180&lt;BR /&gt;// radius of earth = 6371km (constant)&lt;BR /&gt;&lt;BR /&gt;CalcDistances:&lt;BR /&gt;noconcatenate&lt;BR /&gt;load&lt;BR /&gt; zipcode,&lt;BR /&gt; state,&lt;BR /&gt; country,&lt;BR /&gt; Latitude1,&lt;BR /&gt; Longitude1,&lt;BR /&gt; weatherStationID,&lt;BR /&gt; Latitude2,&lt;BR /&gt; Longitude2,&lt;BR /&gt; // the Haversine formula&lt;BR /&gt; (2 *&lt;BR /&gt; (atan2(&lt;BR /&gt; sqrt((sqr(sin(((Latitude2 * Pi() / 180) - (Latitude1 * Pi() / 180)) / 2))&lt;BR /&gt; + ((cos((Latitude1 * Pi() / 180)) * cos((Latitude2 * Pi() / 180)))&lt;BR /&gt; * sqr(sin(((Longitude2 * Pi() / 180) - (Longitude1 * Pi() / 180)) / 2))&lt;BR /&gt; )&lt;BR /&gt; )),&lt;BR /&gt; sqrt((1-(&lt;BR /&gt; sqr(sin(((Latitude2 * Pi() / 180) - (Latitude1 * Pi() / 180)) / 2))&lt;BR /&gt; + ((cos((Latitude1 * Pi() / 180)) * cos((Latitude2 * Pi() / 180)))&lt;BR /&gt; * sqr(sin(((Longitude2 * Pi() / 180) - (Longitude1 * Pi() / 180)) / 2))&lt;BR /&gt; )&lt;BR /&gt; ))&lt;BR /&gt; )))) * 6371 as Distance_km&lt;BR /&gt;resident AllPossibleZipWeatherStationCombinations;&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;Example of input/output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="error loading image" class="jive-image error-loading-image" src="https://community.qlik.com/legacyfs/online/-4196_sourceID:4196" /&gt;&lt;/P&gt;&lt;P&gt;- Trevor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Apr 2011 18:30:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234630#M86017</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2011-04-28T18:30:23Z</dc:date>
    </item>
    <item>
      <title>Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234631#M86018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In many cases, you can probably get away with this:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;,acos(sin(Latitude *pi()/180)*sin(Latitude2*pi()/180)&lt;BR /&gt; +cos(Latitude *pi()/180)*cos(Latitude2*pi()/180)&lt;BR /&gt; *cos(Longitude2*pi()/180 -Longitude*pi()/180))*6371 as Distance&lt;/P&gt;&lt;P&gt;But reading Wikipedia, if you can have very short distances, the Haversine formula is better. But as long as we're shooting for accuracy, it indicates that the Haversine formula has similar numerical errors for points on near exact opposite sides of the earth. Likely much more rare in real data sets than two points close together, but we might as well handle everything. It recommends the spherical case of the Vincenty formula:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;,atan2(sqrt(sqr(cos(Latitude2*pi()/180)&lt;BR /&gt; *sin(Longitude2*pi()/180-Longitude*pi()/180))&lt;BR /&gt; +sqr(cos(Latitude *pi()/180)*sin(Latitude2*pi()/180)&lt;BR /&gt; -sin(Latitude *pi()/180)*cos(Latitude2*pi()/180)&lt;BR /&gt; *cos(Longitude2*pi()/180 -Longitude*pi()/180)))&lt;BR /&gt; ,sin(Latitude *pi()/180)*sin(Latitude2*pi()/180)&lt;BR /&gt; +cos(Latitude *pi()/180)*cos(Latitude2*pi()/180)&lt;BR /&gt; *cos(Longitude2*pi()/180 -Longitude*pi()/180))*6371 as Distance&lt;/P&gt;&lt;P&gt;I haven't checked it carefully, but it seems to produce the right results for a few sample points that admittedly don't test the difficult boundary conditions.&lt;/P&gt;&lt;P&gt;Both of us could probably make our formulas more efficient and easier to read by just adding the Latitude and Longitude in radians to our table temporarily.&lt;/P&gt;&lt;P&gt;Edit: Yeah, that does of course make everything much simpler. See below and attached. I can see that the simple arccosine formula does have problems with points right next to each other. Interestingly, your Haversine formula doesn't match the one on Wikipedia. It's mathematically equivalent I'm sure, but so are all of them.&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;// arccosine: problem when points are very close together&lt;BR /&gt;,acos(sin(Lat1)*sin(Lat2)+cos(Lat1)*cos(Lat2)*cos(Lon2-Lon1))*6371 as "Distance"&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;// Haversine: problem when points are very close to opposite sides of the earth&lt;BR /&gt;,atan2(sqrt(sqr(sin((Lat2-Lat1)/2))+cos(Lat1)*cos(Lat2)*sqr(sin((Lon2-Lon1)/2)))&lt;BR /&gt; ,sqrt(1-(sqr(sin((Lat2-Lat1)/2))&lt;BR /&gt; +cos(Lat1)*cos(Lat2)*sqr(sin((Lon2-Lon1)/2)))))*2*6371 as "Distance 2"&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;// Vincenty: no problems (?)&lt;BR /&gt;,atan2(sqrt(sqr(cos(Lat2)*sin(Lon2-Lon1))&lt;BR /&gt; +sqr(cos(Lat1)*sin(Lat2)-sin(Lat1)*cos(Lat2)*cos(Lon2-Lon1)))&lt;BR /&gt; ,sin(Lat1)*sin(Lat2)+cos(Lat1)*cos(Lat2)*cos(Lon2-Lon1))*6371 as "Distance 3"&lt;/P&gt;&lt;P&gt;Also, an amusing tidbit now that I'm reading the site you linked to:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;"...it is probably worth, in most situations, using either the simpler law of cosines or the more accurate ellipsoidal Vincenty formula in preference to haversine!"&lt;/P&gt;&lt;P&gt;Edit 2: Hmmm, well, if we take the Vincenty results as the right answers, both the Arccosine and Haversine approaches are ever so slightly off for points that are ever so slightly different from exact opposite ends of the earth. I didn't notice that at first. It's the distance between points 4 and 5. The formulas disagree by about 1 mm. Hardly an issue in practice, of course.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2011 01:01:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234631#M86018</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-04-29T01:01:37Z</dc:date>
    </item>
    <item>
      <title>Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234632#M86019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your insight is greatly appreciated. Thanks for your comments, John.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2011 14:43:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234632#M86019</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2011-04-29T14:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234633#M86020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've a list latitude and longitude that is used in a scatter chart and superimposed on google maps. Is there a way to calculate distance between any two coordinates that I select?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rahul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jul 2011 07:25:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234633#M86020</guid>
      <dc:creator />
      <dc:date>2011-07-22T07:25:59Z</dc:date>
    </item>
    <item>
      <title>Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234634#M86021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to using Google maps on Qlikview. I had a task on hand which required me to plot a set of streets/cities of US on the google maps and then find out the distance of the plotted points from the nearest respective highways.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was able to import my data on Qlikview and have the streets plotted on the google map. But I see that I cannot drop points on the nearest highways and then get the distance between the two as we can in Google maps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this feature possible/ available on Qlikview?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be of great assisstance!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many Thanks,&lt;/P&gt;&lt;P&gt;Ritika&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 07:44:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234634#M86021</guid>
      <dc:creator />
      <dc:date>2011-10-10T07:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234635#M86022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Trevor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I went searching the community as a long shot and found gold. Thank you very much for the post - it has saved me hours.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;K&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2014 13:26:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234635#M86022</guid>
      <dc:creator />
      <dc:date>2014-03-07T13:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234636#M86023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is super helpful. I'm looking to use this formula converted to miles, so I looked up the radius of the earth in miles. My question is whether to use miles or nautical miles. I don't fully understand nautical miles, but it sounds like it is the standard for navigating and charting (which is sort of what we're doing here). It appears you are using the straight line radius. Any thoughts or comments?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is a great explanation already, so thanks for sharing!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Jan 2016 21:15:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234636#M86023</guid>
      <dc:creator />
      <dc:date>2016-01-25T21:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234637#M86024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Raul, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this is how i get it done in a simple expression by introducing an additional recnum() column for the table in the data load editor. With the GetSelectedCount() function, this will calculate the distance between two selected geographical coordinates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had also added some 'prompts' and format settings. Hope this helps. (:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank You and have a nice day (:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;BR /&gt;Chong Ee Lian&lt;/P&gt;&lt;P&gt;New to Qlik&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Start of Sample Expression&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(GetSelectedCount(OUTLET,true())=2,&lt;/P&gt;&lt;P&gt;Num(&lt;/P&gt;&lt;P&gt;(ACOS(COS(pi()/180*(90-(MAX({&amp;lt;RECNUM={"$(=Max(RECNUM,1))"}&amp;gt;} LAT))))&lt;/P&gt;&lt;P&gt;*COS(pi()/180*(90-(MAX({&amp;lt;RECNUM={"$(=Max(RECNUM,2))"}&amp;gt;} LAT))))&lt;/P&gt;&lt;P&gt;+&lt;/P&gt;&lt;P&gt;SIN(pi()/180*(90-(MAX({&amp;lt;RECNUM={"$(=Max(RECNUM,1))"}&amp;gt;} LAT))))&lt;/P&gt;&lt;P&gt;*SIN(pi()/180*(90-(MAX({&amp;lt;RECNUM={"$(=Max(RECNUM,2))"}&amp;gt;} LAT))))&lt;/P&gt;&lt;P&gt;*COS(pi()/180*((MAX({&amp;lt;RECNUM={"$(=Max(RECNUM,1))"}&amp;gt;} LONG))-(MAX({&amp;lt;RECNUM={"$(=Max(RECNUM,2))"}&amp;gt;} LONG)))))*6371)&lt;/P&gt;&lt;P&gt;,'#,##0.##', '.' , ',' ) &lt;/P&gt;&lt;P&gt;&amp;amp; 'km'&lt;/P&gt;&lt;P&gt;,if(GetSelectedCount(OUTLET,true())&amp;gt;2,'You Have Selected More than 2 Outlets. Please Select Only 2.'&lt;/P&gt;&lt;P&gt;,if(GetSelectedCount(OUTLET,true())=1,'For Distance Calculations, Please Select 2 Outlets.'&lt;/P&gt;&lt;P&gt;,'No Selection')))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Assumption 1: --- &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Earth's Radius=6371km&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;//Assumption 2: --- Degrees to Radian Conversion --- Rad=(Deg* PI/180)&lt;/P&gt;&lt;P&gt;//Final Output will be in X.XX KM, &lt;/P&gt;&lt;P&gt;//Using Harvesine formula to calculate the distance between two selected geographical coordinates.&lt;/P&gt;&lt;P&gt;//LAT: latitude, LONG: longitude&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Feb 2016 04:01:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234637#M86024</guid>
      <dc:creator>eelianx88</dc:creator>
      <dc:date>2016-02-12T04:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234638#M86025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data as below&lt;/P&gt;&lt;P&gt;Tanle1&lt;/P&gt;&lt;P&gt;Employee&amp;nbsp; latitude&amp;nbsp; longitude&lt;/P&gt;&lt;P&gt;Arnold&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 121&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 130&lt;/P&gt;&lt;P&gt;Beck&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 150&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 72 &lt;/P&gt;&lt;P&gt;Table 2&lt;/P&gt;&lt;P&gt;Factory&amp;nbsp;&amp;nbsp;&amp;nbsp; f_latitude&amp;nbsp; f_longitude&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 211.7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 179.5&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 129&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 150&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to calculate the distance from Arnold to both the factories A and B&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 33.0844px;"&gt;the distance from Beck to both the factories A and B &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 33.0844px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 33.0844px;"&gt;Is it possible to do and there is no relation between the two tables&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2016 15:06:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234638#M86025</guid>
      <dc:creator />
      <dc:date>2016-11-30T15:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234639#M86026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John&lt;/P&gt;&lt;P&gt;i have data in two different tables as follows&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;emp-tab:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;emp_id, lat1, long1&lt;BR /&gt;1, 22.32, 114.17&lt;BR /&gt;2, 22.28, 114.16&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;factory_tab:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fact_ID, lat2, long2&lt;BR /&gt;1, 22.42544, 114.23134&lt;BR /&gt; 2, 22.29540, 114.26860&lt;/P&gt;&lt;P&gt;i'm getting the end results as&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.qlik.com/servlet/JiveServlet/showImage/2-1170101-145459/pastedImage_2.png"&gt;&lt;IMG class="jive-image image-1" height="90" src="https://community.qlik.com/legacyfs/online/145467_pastedImage_2.png" width="297" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;is this correct&lt;/P&gt;&lt;P&gt;and can't we calculate the distance if the data is in two different tables&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Dec 2016 20:23:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234639#M86026</guid>
      <dc:creator />
      <dc:date>2016-12-01T20:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234640#M86027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not correct, and yes we can calculate using two tables. Easiest way is to just move most of the calculation to the front end, but if performance becomes a problem, there are other ways to handle it. See attached.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/145481_Capture.PNG" style="width: 620px; height: 82px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2016 01:23:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234640#M86027</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2016-12-02T01:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234641#M86028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much John again you solved my problem&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Dec 2016 14:38:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234641#M86028</guid>
      <dc:creator />
      <dc:date>2016-12-04T14:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234642#M86029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;I'm struggling with an issue john, the first thought in my mind is you, who can help me out. who can help in any issue&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have&amp;nbsp; data as below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;based on your inputs i have calculated distance between two latitude and longitudes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1, i need to calculate the distance between each employee to every office (this is achieved with your previous inputs)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the main part is&lt;/P&gt;&lt;P&gt;i want three input boxes&amp;nbsp; as below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when i put value in&amp;nbsp; distance inputbox&amp;nbsp; =&amp;nbsp; 0.7 all the offices which are less than 0.7 km&amp;nbsp; to employee should&amp;nbsp; be dispalyed&lt;/P&gt;&lt;P&gt;when i put value in&amp;nbsp; office strength inputbox&amp;nbsp; = 100 all the offices stregth which are less than 100&amp;nbsp; should&amp;nbsp; be dispalyed&lt;/P&gt;&lt;P&gt;when i put value in&amp;nbsp;&amp;nbsp;&amp;nbsp; employee salary rank inputbox&amp;nbsp;&amp;nbsp;&amp;nbsp; = 15&amp;nbsp; top 15 ranked employees should be displayed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;all the above should be displayed in a straight table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as below&lt;/P&gt;&lt;P&gt;output_1&lt;/P&gt;&lt;P&gt;employee&amp;nbsp; emp_lat&amp;nbsp; emp_lang&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; office strength&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; employee salary&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(offices &amp;lt;0.7)&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 50(which is less than 100 )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10 (rank 1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12(varies)&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; z&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40(which is less than 100 )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 (rank 2)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i want for a particular employee how many offices are below 0.7 km(what ever the value provided in input box),&amp;nbsp; whose office strength&amp;nbsp; is less than 100(what ever the value provided in inputbox) and the employee salary by rank (provided in the input box)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2016 18:02:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234642#M86029</guid>
      <dc:creator />
      <dc:date>2016-12-09T18:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234643#M86030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Calculate distance as shown before. Add a Rank field for the salary. Trigger actions to make selections based off the input boxes. See attached.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2016 21:51:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234643#M86030</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2016-12-09T21:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234644#M86031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John Thank you for the reply&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my requiremnt is&amp;nbsp; a staright table &lt;/P&gt;&lt;P&gt;as below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;based on the input boxes values&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/146271_pastedImage_0.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have defined two variables and a set expression as below&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/146272_pastedImage_1.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;i'm using&amp;nbsp; emp_id as dimension&lt;/P&gt;&lt;P&gt;this is my expression in staraight table&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;count&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;({&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Distance&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;"&amp;lt;$(vdistance_office)"&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;}, office_strength&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;"&amp;lt;$(v_strength)"&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;}&amp;gt;}&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;office_id)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;i'm not getting the exat results and my data is associated as below&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;&lt;IMG class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/146276_pastedImage_2.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Dec 2016 11:48:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234644#M86031</guid>
      <dc:creator />
      <dc:date>2016-12-10T11:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234645#M86032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, that's very different from the approach I took, but I think it should work just fine. You should count distinct office_id, not just office_id, but I don't know if that's the problem. Hard to debug what I can't see.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2016 01:38:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/234645#M86032</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2016-12-16T01:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1625668#M446101</link>
      <description>&lt;P&gt;&amp;nbsp;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the formula runs without errors, but it doesn't calculate the measure.&lt;/P&gt;&lt;P&gt;Which format for longitude lattitude is necessary?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Ingo&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 11:01:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1625668#M446101</guid>
      <dc:creator>ingo_lsg</dc:creator>
      <dc:date>2019-09-19T11:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1625670#M446102</link>
      <description>&lt;P&gt;Heres a screenshot of my data&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 11:16:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1625670#M446102</guid>
      <dc:creator>ingo_lsg</dc:creator>
      <dc:date>2019-09-19T11:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1661180#M448786</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;SPAN&gt;Chong Ee Lian,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Could you please give more details about the load procedure?&lt;/P&gt;&lt;P&gt;I could not understand what you have done on introduce an additional recnum() column&amp;nbsp;&lt;SPAN&gt;for the table in the data load editor.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance + regards&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2019 12:18:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1661180#M448786</guid>
      <dc:creator>LZucco</dc:creator>
      <dc:date>2019-12-28T12:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Haversine formula to find distance between two lat/long points</title>
      <link>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1830290#M1214445</link>
      <description>&lt;P&gt;Hi, this is an old thread, but I needed a solution and have written some code using the Vicenty formula if anyone finds its useful.&amp;nbsp; I stole&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/6077"&gt;@johnw&lt;/a&gt;&amp;nbsp;'s code above.&lt;/P&gt;&lt;P&gt;For ease of understanding (and copy and paste), I broke the QlikView Load statement into 3 preceding loads:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Trace Calculating distance on a sphere;

// This is a series of preceding loads, executed in the order Step 1... Step 2...
NoConcatenate
Distances:
// Step 3: Convert the raw distance into convenient common units
Load
	*,
	
	Round ( [Distance Vicenty], 0.1 ) 				as [Distance Vicenty km],
	Round ( [Distance Vicenty] * 1000 ) 			as [Distance Vicenty meters],
	Round ( [Distance Vicenty] * 0.6213712, 0.1 ) 	as [Distance Vicenty miles],
;
// Step 2: Calculate the distance using the Vicenty formula and radian fields
Load
	*,
	
// Vincenty formula
atan2(
	sqrt(
		sqr(cos(Lat2Radians)*sin(Lon2Radians-Lon1Radians))
		+
		sqr(cos(Lat1Radians)*sin(Lat2Radians)-sin(Lat1Radians)*cos(Lat2Radians)*cos(Lon2Radians-Lon1Radians))
	),
	sin(Lat1Radians)*sin(Lat2Radians)
	+
	cos(Lat1Radians)*cos(Lat2Radians)*cos(Lon2Radians-Lon1Radians)
) * 6371 as [Distance Vicenty]

;
// Step 1: Generate radian fields
// Replace Lat1, Lat2, Lon1 and Lon2 with the name of your fields
Load
	*,
	(Lat1 * Pi() / 180)	as Lat1Radians,
	(Lat2 * Pi() / 180)	as Lat2Radians,
	(Lon1 * Pi() / 180)	as Lon1Radians,
	(Lon2 * Pi() / 180)	as Lon2Radians
Resident TestLocations
;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This results in some extra fields but they can be dropped easily and this is much easier to understand.&amp;nbsp; I have four actual places as test data and the QVW attached calculates the Vicenty distance to the same end location (Salt Lake City airport).&lt;/P&gt;&lt;P&gt;The file DistanceCalculations.qvw is attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Aug 2021 00:41:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Haversine-formula-to-find-distance-between-two-lat-long-points/m-p/1830290#M1214445</guid>
      <dc:creator>kevinpintokpa</dc:creator>
      <dc:date>2021-08-21T00:41:10Z</dc:date>
    </item>
  </channel>
</rss>

