Power BI - 根据 Lat/Lng 查找最近的位置 [英] Power BI - Find closest location based on Lat/Lng

查看:42
本文介绍了Power BI - 根据 Lat/Lng 查找最近的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Power BI 和 DAX 的新手,所以希望你能帮助我.

I am new to Power BI and DAX, so I hope you can help me.

我有两个没有任何关系的表:表 A 包含跟踪位置的纬度/经度和日期.表 B 包含所有体育场的纬度/经度和名称.

I have two tables without any relationship: Table A contains lat/lng and date of tracked positions. Table B contains lat/lng and names of all stadiums.

我想找到跟踪位置附近最近的体育场.如果可能的话,我想验证该位置是否在该体育场的特定半径内.

I want to find the closest stadium near the tracked position. Also if possible I want to validate, if the position was in a specific radius of that stadium.

非常感谢任何帮助.

推荐答案

这是一种可能的方法:

首先,使用 Haversine 函数计算最小距离.

First, calculate the minimal distance using the Haversine function.

将此作为计算列添加到您的 Tracked 表中.

Add this 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))

在此公式中,3959 是以英里为单位的地球半径.

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

我们现在可以匹配距离以找到最近的体育场:

We can now match up distances to 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]))

<小时>

注意:我对这些值进行了四舍五入以避免可能的浮点错误不匹配.这可能是必要的,也可能不是.


Note: I rounded the values to avoid not matching from possible floating point errors. This may or may not be necessary.

这篇关于Power BI - 根据 Lat/Lng 查找最近的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆