Forum Discussion
SilentKernel
5 months agoFrequent Visitor
Display Stores Within Radius for Multiple ZIP Codes
Hi everyone, I am working on a Power BI report using Azure Maps. I have a STORE table that contains: Store name Address Latitude Longitude I also have a ZIPCODE table that contains all vali...
SilentKernel
4 months agoFrequent Visitor
I’ve created the following measure to calculate the Haversine distance between locations in the stores table and the selected ZIP codes from the zipcode table. However, when I display this measure in a table or matrix visual, the distances shown are incorrect. Additionally, my requirement is to display the calculated distances both on Azure Maps and in a table visual for all user‑selected ZIP codes in my report. Could you explain how I can achieve this behavior properly?
DistanceToPLZ =
MINX(
CROSSJOIN(
stores,
SELECTCOLUMNS(
ALLSELECTED(zipcode),
"GeoLat", zipcode[lat],
"GeoLon", zipcode[long]
)
),
VAR Lat1 = stores[Latitude]
VAR Lon1 = stores[Longitude]
VAR Lat2 = [GeoLat]
VAR Lon2 = [GeoLon]
VAR R = 6371
VAR dLat = RADIANS(Lat2 - Lat1)
VAR dLon = RADIANS(Lon2 - Lon1)
VAR a =
SIN(dLat/2)^2 +
COS(RADIANS(Lat1)) *
COS(RADIANS(Lat2)) *
SIN(dLon/2)^2
VAR c = 2 * ATAN(DIVIDE(SQRT(a),SQRT(1-a)))
RETURN R * c
)