【问题标题】:PowerPivot: Function for distance between two points ErrorPowerPivot:两点之间距离的函数错误
【发布时间】:2021-12-06 20:46:32
【问题描述】:

我目前正在使用 powerpivot,并添加了一个列来为所有行创建一个计算字段。该函数的目的是通过获取两个邮政编码的纬度和经度来找到它们之间的距离;此功能始终在 excel 工作表中有效,但是当我尝试在电源查询中使用相同的功能时,它不起作用。我之所以对这个函数使用 power query 是因为数据集超过 4,000,000 行...

我正在使用下面的函数,它返回为“#ERROR”

=ACOS(COS(RADIANS(90-'Origin vs Destination w PKG'[Latitude]))*COS(RADIANS(90-'Origin vs Destination w PKG'[DLatitude]))+SIN(RADIANS(90-'Origin vs Destination w PKG'[Latitude]))*SIN(RADIANS(90-'Origin vs Destination w PKG'[DLatitude]))*COS(RADIANS('Origin vs Destination w PKG'[Longitude]-'Origin vs Destination w PKG'[DLongitude])))*3958.8

上面是函数。有谁知道如何让两个坐标之间的距离函数在 PowerPivot 中工作?

非常感谢

【问题讨论】:

    标签: excel excel-formula powerquery spreadsheet powerpivot


    【解决方案1】:

    假设 Table1 有 4 列 [Latitude_1], [Longitude_1], [Latitude_2], [Longitude_2] 并且坐标是十进制的 [38.892456, -74.0247852] 然后下面的代码生成以英里为单位的位置之间的距离(将 3959 更改为6371 公里)使用公式:

    =ACOS(SIN(lat1)*SIN(lat2)+COS(lat1)*COS(lat2)*COS(lon2-lon1))*3959

    在powerquery代码中是:

    = Number.Acos(Number.Sin(([Latitude_1] / 180) * Number.PI) * Number.Sin(([Latitude_2] / 180) * Number.PI) + Number.Cos(([Latitude_1] / 180) * Number.PI) * Number.Cos(([Latitude_2] / 180) * Number.PI) * Number.Cos( ([Longitude_2] / 180) * Number.PI-([Longitude_1] / 180) * Number.PI)) * 3959)
    

    完整代码示例:

    let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "DistanceMiles", each Number.Acos(Number.Sin(([Latitude_1] / 180) * Number.PI) * Number.Sin(([Latitude_2] / 180) * Number.PI) + Number.Cos(([Latitude_1] / 180) * Number.PI) * Number.Cos(([Latitude_2] / 180) * Number.PI) * Number.Cos( ([Longitude_2] / 180) * Number.PI-([Longitude_1] / 180) * Number.PI)) * 3959),
    in #"Added Custom"
    

    【讨论】:

    • 感谢您的快速响应,但这是针对 powerquery 而不是 power BI
    • 那个示例代码是powerquery M代码,所以不知道是什么问题
    猜你喜欢
    • 2012-12-31
    • 1970-01-01
    • 2019-01-23
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 2010-10-30
    相关资源
    最近更新 更多