Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have a table excel (kode store, name store, latitude, longitude) with a total of 25 outlet. I want to make it efficient to merge several stores considering the closest distance.
How can I find the nearest stores and the nearest stores distance (excluded the store itself because it will return a value of 0.0 km)
I use some formula but return a value of 0.0 km because the store itself
For example closestest store upc ahmad yani is upc mall cipto about 1 kilometer
data pbix here : http://bit.ly/distance_powerbi
Is there anyone who can help me ..
Hoping this solution may be of interest to others.
Thanks,
Theo
Solved! Go to Solution.
Hi @theoandino
For the distance you just need to exclude the current store from the search (look at the FILTER() as base table for the MINX()):
DISTANCE_TO_CLOSTEST_STORE_(KM) =
VAR Lat1 = outlet_distance[LATITUDE]
VAR Lng1 = outlet_distance[LONGITUDE]
VAR name_ = outlet_distance[STORE_NAME]
VAR P =
DIVIDE ( PI (), 180 )
RETURN
MINX (
FILTER ( outlet_distance, outlet_distance[STORE_NAME] <> name_ ),
VAR Lat2 = outlet_distance[LATITUDE]
VAR Lng2 = outlet_distance[LONGITUDE]
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
)
and for the name of the store:
CLOSEST_STORE =
VAR Lat1 = outlet_distance[LATITUDE]
VAR Lng1 = outlet_distance[LONGITUDE]
VAR name_ = outlet_distance[STORE_NAME]
VAR P =
DIVIDE ( PI (), 180 )
VAR auxT_ =
ADDCOLUMNS (
FILTER ( outlet_distance, outlet_distance[STORE_NAME] <> name_ ),
"Distance_",
VAR Lat2 = outlet_distance[LATITUDE]
VAR Lng2 = outlet_distance[LONGITUDE]
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
)
VAR minVal_ =
MINX ( auxT_, [Distance_] )
RETURN
MINX ( FILTER ( auxT_, [Distance_] = minVal_ ), outlet_distance[STORE_NAME] )
Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hi @theoandino
For the distance you just need to exclude the current store from the search (look at the FILTER() as base table for the MINX()):
DISTANCE_TO_CLOSTEST_STORE_(KM) =
VAR Lat1 = outlet_distance[LATITUDE]
VAR Lng1 = outlet_distance[LONGITUDE]
VAR name_ = outlet_distance[STORE_NAME]
VAR P =
DIVIDE ( PI (), 180 )
RETURN
MINX (
FILTER ( outlet_distance, outlet_distance[STORE_NAME] <> name_ ),
VAR Lat2 = outlet_distance[LATITUDE]
VAR Lng2 = outlet_distance[LONGITUDE]
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
)
and for the name of the store:
CLOSEST_STORE =
VAR Lat1 = outlet_distance[LATITUDE]
VAR Lng1 = outlet_distance[LONGITUDE]
VAR name_ = outlet_distance[STORE_NAME]
VAR P =
DIVIDE ( PI (), 180 )
VAR auxT_ =
ADDCOLUMNS (
FILTER ( outlet_distance, outlet_distance[STORE_NAME] <> name_ ),
"Distance_",
VAR Lat2 = outlet_distance[LATITUDE]
VAR Lng2 = outlet_distance[LONGITUDE]
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
)
VAR minVal_ =
MINX ( auxT_, [Distance_] )
RETURN
MINX ( FILTER ( auxT_, [Distance_] = minVal_ ), outlet_distance[STORE_NAME] )
Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
I know this is a lot later, but do you know how to add in a check within this? Specifically, I need to pull the closest store that sells an item if sold out at the current.
Thanks for the answer......
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
97 | |
86 | |
70 | |
62 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |