Calculating Distances between Locations

  • Calculating Distances between Locations

    Posted by DSC Communities on August 29, 2018 at 4:26 pm
    • Dean Stanberry

      Member

      August 29, 2018 at 4:26 PM

      First – I’m relativelyĀ new to Power BI.Ā  I am trying to build a report that will display the distance between a selected “From” zip code and other addresses within a selected distance (miles).Ā  My fact table contains a long list of project addresses (city, state, zip) and other project-related data.Ā  I have a lookup table that lists all U.S. zip codes along with the city, state, latitude, and longitude.

      Ideally, I would select a “From” zip code and a “Distance” in miles, and the report would show me the list of sites that fall within the “Distance” or less.

      I had some help creating a measure to do the distance math between two sets of latitude & longitude (see below).Ā  However, I can’t seem to get it to compute the distances for each row (record) in the project list.Ā  Ā I’ve attached some screenshots to show some of the structure and report screen.
      MEASURE ——————————————————————————————————————————————-
      Miles =
      var Lat1 = LOOKUPVALUE(ZipCodes[Zip_Latitude],ZipCodes[Zip_Code], min(‘Recruiting Test-2′[Zip_Code]))
      var Lng1 = LOOKUPVALUE(ZipCodes[Zip_longitude],ZipCodes[Zip_Code], MIN(‘Recruiting Test-2′[Zip_Code]))

      var Lat2 = LOOKUPVALUE(ZipCodes[Zip_longitude],ZipCodes[Zip_Code], From_Zip[From_Zip Value])
      var Lng2 = LOOKUPVALUE(ZipCodes[Zip_longitude],ZipCodes[Zip_Code], From_Zip[From_Zip Value])
      —- Algorithm here —–
      var P = DIVIDE( PI(), 180 )
      var A = 0.5 – COS((Lat2-Lat1) * p)/2 +
      COS(Lat1 * p) * COS(lat2 * P) * (1-COS((Lng2- Lng1) * p))/2
      var final = 12742 * ASIN((SQRT(A)))
      return (final * 0.621371)
      ———————————————————————————————————————————————————–
      I know I’m missing something in how to select individual records for the measure, but not sure where to go to figure it out.Ā  Any assistance would be greatly appreciated.

      ——————————
      Dean Stanberry
      Director-FM Services
      Denver CO
      720-877-1521
      ——————————

    • John Broomfield

      Member

      August 30, 2018 at 2:49 AM

      Hi,

      I worked on some similar but did all my distance calculations in SQL Server using spatial functions, and then presented in Power BI. you can read about my approach here –Ā Mapping Adventures in Power BI

      There is a nice video here on calculating distance between 2 points as well –Ā Calculate the distance between two points/locations/coordinates in Power BI

      Hopefully these help
      Cheers
      John

      ——————————
      John Broomfield
      Business Intelligence Analyst

      ——————————
      ——————————————-

    • Marshall Berg

      Member

      August 30, 2018 at 10:45 AM

      This looks like something I might like to address over Labor Day weekend. Please feel free to share anything else relevant. mberg@kpikc.com

      ——————————
      Marshall Berg
      Kansas City, MO
      8165851238
      ——————————
      ——————————————-

    • Del Swingle

      Member

      August 30, 2018 at 3:31 PM

      Dean,

      If I understand your request, in your report you’d like to be able to control your “Miles” measure with a slicer (single selection of a desired zip code). Have a look at the attach file to if this is what you’re after.Ā 

      Del

      ——————————
      Del Swingle
      WA
      ——————————
      ——————————————-

    • Brandon West

      Member

      December 6, 2018 at 4:37 PM

      Del,Ā 
      Your file is perfectly doing what I had in mind.Ā  Would you mind replying to my email address and helping me convert your file to use the type of data I have?Ā  It is very close.Ā Ā 

      Thank you,
      Brandon
      brandon.west@shawinc.com

      ——————————
      Brandon West
      Business Analyst II
      Shaw Industries
      Chatsworth GA
      706-532-6052
      ——————————
      ——————————————-

    DSC Communities replied 7 years, 1 month ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘Calculating Distances between Locations’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!