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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
ahmad1111
Frequent Visitor

I Need help with a formula to calculate distance from point A to B

Hi so below are just small example of but dont take the cells with from and to and distance as the correct ones but i just posted it as example because i have big data 5000 rows in my excel so what i actually need is i get an order that order will have plant and unloading point code (as my site name thus from all 5000 rows you can get any for example from below point A is lets say A001-422 and point B is A001-422/477 and issue is since data is big i cant just go one site and check with all other 4999 rows to see which city each site belongs to so i need a way for power bi to check when an order comes and excel updates which is my data source and linked to my power bi then power bi should give me the fixed distance that i have in my excel thus distance only linked as city to city based and not site to site based which is what i recieve when order comes so in short order comes as site a to site b and i need to convert that site to its respective city that it belongs to based on the excel i have and then give the distance

 

PlantUnloading Point CodeUnloading Point NameRegionCountry/Region KeyCityFrom LocationTo LocationDistance In KM
A001422BERRI B-221 GAS PLANT MAINTENANCEZEASABERRI   
A001422/470BERRI B-221 LIQUID RECOVERY (PLT 470)ZEASABERRI GHAZAL1,551
A001422/474BERRI GAS SWEETINING PLANTZEASABERRI UTHMANIYAH227
A001422/476BERRI B-1054 UTILITIES PLANTZEASABERRI BAISH MAZALIJ1,234
A001422/ACSBERRI B-221, MAINTENANCE A/C SHOPZEASABERRI BAISHAL-MUBARRAZ1,394
A001422/ELSBERRI B-221, MAINTENANCE ELECTRICAL SHOPZEASABERRI BAISHBIRALGHANEM968
A001422/ENGBERRI B-221, GAS PLANT MAINTEMANCEZEASABERRI BAISHKHAMIS MUSHAIT165
A001422/F13BERRI B-F14, RULF. PRILL PLANT F13ZEASABERRI BAISHMAZALIJ1,234
A001422/F14BERRI B-F14, PLT F14ZEASABERRI   
A001422/F18BERRI B-1054, F18 COGENERATIONZEASABERRI   
A001422/F20BERRI B-1054, ETHANE RECOVERYZEASABERRI   
A001422/IEDBERRI B-201, INSTRUMENT & DIG SHOPZEASABERRI   
A001422/MASBERRI B-201, ROTATING EQUIPMENT SHOPZEASABERRI   
A001422/MCUBERRI B-210, BGP MATL. COORDINATION UNITZEASABERRI   
A001422/MESBERRI B-1053, MAINTENANCE METALS SHOPZEASABERRI   
A001422/PIUBERRI B-1054, USER PICK-UPZEASABERRI   
A001422/R64BERRI B-471 SULFUR PLANT,ALLTRAIN PLT471ZEASABERRI   
A001422/R68BERRI B-221, OFF-SITE AREZEASABERRI   
A001422/R69BERRI B-475, ETHANE PLANT PLT 475ZEASABERRI   
A001422/RVSBERRI B-201 RVS AT BERRI G. PLANT MAINT.ZEASABERRI   
A001422/T&IBERRI B-221, T&I YARDZEASABERRI   
A001C300RASTANURA STORESZEASARAS TANURA   
A001C321JUAYMAH B-321, STORESZEASAJUAYMAH   
A001C422BERRI GAS PLANT MAINZEASABERRI   
A001H01AJUAYMAH MSSD REVERSE ENGINEERING CENTERZEASAJUAYMAH   
A002531SHEDGUM STORES UNITZEASASHEDGUM   
A002532/TXIUTHMANIYAH  GAS PLANT TAXI MATERIALSZEASAUTHMANIYAH   
A002566UTHMANIYAH  NGL FIRE CONTROL UNITZEASAUTHMANIYAH   
2 REPLIES 2
bhanu_gautam
Super User
Super User

@ahmad1111 Create a table that maps each site to its respective city. This table will help you convert site codes to city names.

Create relationships between your main data table and the mapping table based on the site codes

 

Create calculated columns in your main data table to convert site codes to city names using DAX.

From City = RELATED('MappingTable'[City])
To City = RELATED('MappingTable'[City])

 

Create a measure to calculate the distance between cities. Assuming you have a table with distances between cities, you can use a DAX

Distance =
VAR FromCity = [From City]
VAR ToCity = [To City]
RETURN
CALCULATE(
MAX('DistanceTable'[Distance In KM]),
'DistanceTable'[From Location] = FromCity,
'DistanceTable'[To Location] = ToCity
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam thanks for your reply i got bit confused little bit is it possible to give me in steps mainly the first steps regarding creating table and relationships as i got lost with the mapping table and main data table as in do you mean main table is my excel with the sites and cities and distance and mapping table is a new table i create in power bi but if so then what do you put in it or do with it within power bi so steps will be very helpful thanks

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.