Locating closest match based on Latitude Longitude

0 votes
So, I have, on Power BI, 2 tables with no relationship. One table contains Latitude & Longitude, along with dates, of positions tracked. And the other table contains the same coordinates but with names of Stadiums.

What I want to do is find the closest stadium near the tracked position.

Can anyone help me out? Thanks in advance!
Jan 2, 2019 in Power BI by Upasana
• 8,620 points
2,781 views

1 answer to this question.

0 votes

First of all, we need to use the Haversine function to calculate the minimal distance.

This is to be added as a calculated column to your tracked table.

Nearest = 
    MINX(Stadiums,
    ROUND(2 * 3959 *
        ASIN(SQRT(
            SIN((Stadiums[Lat] - Tracked[Lat]) * PI()/360)^2 +
            COS(Tracked[Lat] * PI()/180) * COS(Stadiums[Lat] * PI()/180) *
                SIN((Stadiums[Lon] - Tracked[Lon]) * PI()/360)^2)), 1))

In this formula, 3959 is the radius of the Earth in miles.

Now, to match up distances & find the nearest stadium:

Stadium = CALCULATE(MAX(Stadiums[Stadium]),
              FILTER(Stadiums,
                  ROUND(2 * 3959 *
                      ASIN(SQRT(
                          SIN((Stadiums[Lat] - Tracked[Lat]) * PI()/360)^2 +
                          COS(Tracked[Lat] * PI()/180) * COS(Stadiums[Lat] * PI()/180) *
                          SIN((Stadiums[Lon] - Tracked[Lon]) * PI()/360)^2)), 1)
                  = Tracked[Nearest]))

PS: The values are rounded to avoid not matching from possible floating point errors. It's not really a necessary step.

answered Jan 2, 2019 by Shubham
• 13,490 points

Related Questions In Power BI

0 votes
1 answer

How to show visualization (map) based on latitude and longitude points in power BI?

Follow the below steps: 1. Select the map ...READ MORE

answered Oct 18, 2019 in Power BI by anonymous
• 3,450 points
2,678 views
0 votes
3 answers

How to create final table based on Joins of two tables in power BI?

To do so, follow these steps: From the ...READ MORE

answered Dec 16, 2020 in Power BI by Gitika
• 65,910 points
53,502 views
0 votes
1 answer

How do I label bar graph with different colors based on values from different slicers?

If the user selects only one value ...READ MORE

answered May 21, 2019 in Power BI by Avantika
• 1,520 points
1,215 views
+1 vote
1 answer

Selecting based on filters

Hi,  If you have more than one table ...READ MORE

answered Aug 12, 2019 in Power BI by anonymous
• 33,030 points
633 views
0 votes
1 answer

DAX EARLIER() function in Power Query

Solutions in the code below. Notice that ...READ MORE

answered Oct 1, 2020 in Power BI by Gitika
• 65,910 points
2,455 views
0 votes
1 answer

DAX / PowerPivot query functions to spread aggregated values over time period

The solution below assumes a table called ...READ MORE

answered Oct 5, 2020 in Power BI by Gitika
• 65,910 points
1,035 views
0 votes
1 answer

Excel PowerPivot DAX Calculated Field

You should create a relationship between each ...READ MORE

answered Oct 5, 2020 in Power BI by Gitika
• 65,910 points
376 views
0 votes
1 answer

PowerPivot DAX - Dynamic Ranking Per Group (Min Per Group)

Firstly create a basic measure [Amount] to sum the ...READ MORE

answered Nov 18, 2020 in Power BI by Gitika
• 65,910 points
1,488 views
0 votes
1 answer

Power BI : Time-based drill downs powered by Azure Data Warehouse

I don't really think you need to ...READ MORE

answered Oct 29, 2018 in Power BI by Shubham
• 13,490 points
634 views
0 votes
2 answers

Can I get rid of the grey border on the report visuals with power bi embedded?

It's just a simple css code to ...READ MORE

answered Apr 19, 2020 in Power BI by Prateek Mehta
4,509 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP