<?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: Going the Distance in Quick Measures Gallery</title>
    <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3263161#M978</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp;What do you mean by -&amp;nbsp;&lt;SPAN&gt;c is the main measure and then you need to multiple this by the radius of the earth in either km, miles, etc.????&lt;BR /&gt;Isn't this the complete solution or there is something we have to multiply at the end after this whole piece of code?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also for me, it shows '0' in the distance calculation.&lt;BR /&gt;Note- i have only 1 table having both to &amp;amp; from locations in the same table and I am using 'SELECTEDVALUE' intead of 'LOOKUP' for column reference still it gives me 0.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Jun 2023 06:23:40 GMT</pubDate>
    <dc:creator>jaisveer21</dc:creator>
    <dc:date>2023-06-01T06:23:40Z</dc:date>
    <item>
      <title>Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963267#M423</link>
      <description>&lt;P&gt;Uses the Haversine formula to compute the distance between the latitudes and longitudes of two points.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;c = 
    VAR __FromCity = SELECTEDVALUE('From City'[City])
    VAR __ToCity = SELECTEDVALUE('To City'[City])
    VAR __FromLat = LOOKUPVALUE('Table'[Latitude],'Table'[City],__FromCity)
    VAR __ToLat = LOOKUPVALUE('Table'[Latitude],'Table'[City],__ToCity)
    VAR __FromLong = LOOKUPVALUE('Table'[Longitude],'Table'[City],__FromCity)
    VAR __ToLong = LOOKUPVALUE('Table'[Longitude],'Table'[City],__ToCity)
    VAR __distanceLong = RADIANS(__ToLong - __FromLong)
    VAR __distanceLat = RADIANS(__ToLat - __FromLat)
    VAR __a = (SIN(__distanceLat/2))^2 + COS(RADIANS(__FromLat)) * COS(RADIANS(__ToLat)) * SIN((__distanceLong/2))^2
    VAR __y = SQRT(__a)
    VAR __x = SQRT(1 - __a)
    VAR __atan2 = 
        SWITCH(
            TRUE(),
            __x &amp;gt; 0, ATAN(__y/__x),
            __x &amp;lt; 0 &amp;amp;&amp;amp; __y &amp;gt;= 0, ATAN(__y/__x) + PI(),
            __x &amp;lt; 0 &amp;amp;&amp;amp; __y &amp;lt; 0, ATAN(__y/__x) - PI(),
            __x = 0 &amp;amp;&amp;amp; __y &amp;gt; 0, PI()/2,
            __x = 0 &amp;amp;&amp;amp; __y &amp;lt; 0, PI()/2 * (0-1),
            BLANK()
        )
    VAR __c = 2 * __atan2
RETURN
    __c&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;c is the main measure and then you need to multiple this by the radius of the earth in either km, miles, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, this does not account for the elliptical shape of the Earth so don't use it for anything besides estimation as you could be off a few miles over long distances.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiNWYwYTBjZjEtZGIxNi00NWExLWI5MzMtNjJlZDg5MTA1ZDU2IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 07:06:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963267#M423</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-05-13T07:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963274#M424</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp; This is great, looking forward to seeing the final distance calculation.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 20:07:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963274#M424</guid>
      <dc:creator>MYDATASTORY</dc:creator>
      <dc:date>2020-03-07T20:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963285#M425</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="114541" data-lia-user-login="MYDATASTORY" class="lia-mention lia-mention-user"&gt;MYDATASTORY&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OK, I downloaded the UK Postal Code latitudes and longitudes from here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.freemaptools.com/download-uk-postcode-lat-lng.htm" target="_blank"&gt;https://www.freemaptools.com/download-uk-postcode-lat-lng.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You guys sure have a lot of postal codes, apparently about 1.7M of them and since they are unique as well as the latitudes and longitudes, well, it makes for a fairly sizeable file.&amp;nbsp;Anyway, I went ahead and implemented a few columns and such to get the distances.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, they only allow a maximum upload file size of 50MB and the file is nearly twice that. So I am uploading to my personal OneDrive and will share out a file from there. Hang tight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 20:40:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963285#M425</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-03-07T20:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/2064849#M765</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp;!! This worked perfectly for me. Much appriciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 16:52:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/2064849#M765</guid>
      <dc:creator>alissa</dc:creator>
      <dc:date>2021-09-08T16:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3019117#M942</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp;this is brilliant and works well. I have an issue where I am using "From" and "To" postcodes but in some cases I do not know the "To" postcode (so that field is blank). This is then giving me a ridiculously huge number. Do you have a suggestion for how I can get it to either give me a figure of 0 or say "unknown" if one of the postcodes is unknown? Any help would be much appreciated. I'm still new to DAX and can't figure out the best way to do this.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 11:40:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3019117#M942</guid>
      <dc:creator>fran_parrett</dc:creator>
      <dc:date>2023-01-13T11:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3019416#M943</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="498269" data-lia-user-login="fran_parrett" class="lia-mention lia-mention-user"&gt;fran_parrett&lt;/a&gt;&amp;nbsp;Couple thoughts, let's say that one of your postcodes is blank and that is a substitute for City in the example. You could do this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;c = 
    VAR __FromCity = SELECTEDVALUE('From City'[City])
    VAR __ToCity = SELECTEDVALUE('To City'[City])
    VAR __FromLat = LOOKUPVALUE('Table'[Latitude],'Table'[City],__FromCity)
    VAR __ToLat = LOOKUPVALUE('Table'[Latitude],'Table'[City],__ToCity)
    VAR __FromLong = LOOKUPVALUE('Table'[Longitude],'Table'[City],__FromCity)
    VAR __ToLong = LOOKUPVALUE('Table'[Longitude],'Table'[City],__ToCity)
    VAR __distanceLong = RADIANS(__ToLong - __FromLong)
    VAR __distanceLat = RADIANS(__ToLat - __FromLat)
    VAR __a = (SIN(__distanceLat/2))^2 + COS(RADIANS(__FromLat)) * COS(RADIANS(__ToLat)) * SIN((__distanceLong/2))^2
    VAR __y = SQRT(__a)
    VAR __x = SQRT(1 - __a)
    VAR __atan2 = 
        SWITCH(
            TRUE(),
            __x &amp;gt; 0, ATAN(__y/__x),
            __x &amp;lt; 0 &amp;amp;&amp;amp; __y &amp;gt;= 0, ATAN(__y/__x) + PI(),
            __x &amp;lt; 0 &amp;amp;&amp;amp; __y &amp;lt; 0, ATAN(__y/__x) - PI(),
            __x = 0 &amp;amp;&amp;amp; __y &amp;gt; 0, PI()/2,
            __x = 0 &amp;amp;&amp;amp; __y &amp;lt; 0, PI()/2 * (0-1),
            BLANK()
        )
    VAR __c = 2 * __atan2
    VAR __Result = IF( __FromCity = BLANK() || __ToCity = BLANK(), 0, __c)
RETURN
    __Result&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 13 Jan 2023 13:59:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3019416#M943</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2023-01-13T13:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3019489#M944</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp;thank you so much. Yes the city was substituted for postcodes as I needed it on a much more local scale. This worked perfectly though! I really appreciate your help.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 14:22:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3019489#M944</guid>
      <dc:creator>fran_parrett</dc:creator>
      <dc:date>2023-01-13T14:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3263161#M978</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp;What do you mean by -&amp;nbsp;&lt;SPAN&gt;c is the main measure and then you need to multiple this by the radius of the earth in either km, miles, etc.????&lt;BR /&gt;Isn't this the complete solution or there is something we have to multiply at the end after this whole piece of code?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also for me, it shows '0' in the distance calculation.&lt;BR /&gt;Note- i have only 1 table having both to &amp;amp; from locations in the same table and I am using 'SELECTEDVALUE' intead of 'LOOKUP' for column reference still it gives me 0.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 06:23:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3263161#M978</guid>
      <dc:creator>jaisveer21</dc:creator>
      <dc:date>2023-06-01T06:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Going the Distance</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3263852#M979</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="569342" data-lia-user-login="jaisveer21" class="lia-mention lia-mention-user"&gt;jaisveer21&lt;/a&gt;&amp;nbsp;Download the PBIX associated with this post and you will see how to use the measure. I made it generic so that you could use it for either miles or kilometers.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 12:44:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/3263852#M979</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2023-06-01T12:44:38Z</dc:date>
    </item>
  </channel>
</rss>

