let
// Paramètres depuis Excel
VILLES = Excel.CurrentWorkbook(){[Name="T_Ville"]}[Content],
VilleDepart = VILLES{0}[V1],
VilleArrivee = VILLES{0}[V2],
// Chargement et transformation des données
Source = Json.Document(Web.Contents("https://www.data.gouv.fr/fr/datasets/r/ef85cdf0-28ed-41d1-81ee-95fbde2e6752")),
A = Table.FromRecords(Source, {"geo_point_2d", "dep_name", "com_name_upper"}),
B = Table.TransformColumns(A, {{"geo_point_2d", each [lon = _[lon], lat = _[lat]], type record},{"com_name_upper", each _, type text}}),
C = Table.ExpandRecordColumn(B, "geo_point_2d", {"lon", "lat"}, {"geo_point_2d.lon", "geo_point_2d.lat"}),
D = Table.ExpandListColumn(C, "dep_name"),
E = Table.RenameColumns(D,{{"geo_point_2d.lon", "longitude"}, {"geo_point_2d.lat", "latitude"}, {"dep_name", "Département"}, {"com_name_upper", "Communes"}}),
F = Table.SelectRows(E, each ([Communes] = VilleDepart or [Communes] = VilleArrivee)),
lat1=F[latitude]{0}/180*Number.PI,lat2=F[latitude]{1}/180*Number.PI,long1=F[longitude]{0}/180*Number.PI,long2=F[longitude]{1}/180*Number.PI,
FIN = #table({"Distance (en KM)"},{{Number.Round(Number.Acos(Number.Sin(lat1) * Number.Sin(lat2) + Number.Cos(lat1) * Number.Cos(lat2) * Number.Cos(long2-long1)) * 6371, 2)}})
in
FIN