Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
HenryJS
Post Prodigy
Post Prodigy

DAX Long / Lat calculation not working

Hi all,

 

I input the below DAX to calculate distance from rows in CandPost table from Bicester Site table.

 

Distance From Compound =
var Lat1 = MIN('CandPost'[Latitude])
var Lng1 = MIN('CandPost'[Longitude])
 
var Lat2 = MIN('Bicester Site'[Latitude])
var Lng2 = MIN('Bicester Site'[Longitude])
---- 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
 
It returned the same distance for each row?

 

1. Bicester Site table

BicesterSite.PNG

 

 

2. CandPost table

CandPost2.PNG

 

Thanks,

 

Henry

4 REPLIES 4
v-lid-msft
Community Support
Community Support

Hi @HenryJS ,

 

How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

When you create a column, the min, max will go across the column and give the same value. Is that is what you are trying? else you need to reconsider the logic or create a measure.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

 

I want to create a column in 'CandPost' which calculates the distance between each 'CandidateRef' from the longitude/latitude in 'Bicester Site' table.

 

This would be a different km value for each candidate ref as they are all in different locations.

 

Can you adivse? I'm stuck

 

Thanks,

 

Henry

Hi @HenryJS ,

 

We can try to create a calculated column using following dax to meet you requirement:

 

Distance From Compound =
VAR Lat1 = [Latitude]
VAR Lng1 = [Longitude]
VAR Lat2 =
    MIN ( 'Bicester Site'[Latitude] )
VAR Lng2 =
    MIN ( 'Bicester Site'[Longitude] ) ---- 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


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.