March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
I got the below query to conver the easting & northing to long, lat coordinates, but it shows an error (Token ',' expected) and I don't know why!
let
Source = Excel.Workbook(File.Contents("C:\Area.xlsx"), null, true),
Area_All_X_Y_Table = Source{[Item="Area_All_X_Y",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Area_All_X_Y_Table,{{"X", Int64.Type}, {"Y", Int64.Type}, {"DIS", type number}, {"Offset Well", type text}, {"Name", type text}, {"Column1", Int64.Type}}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Area", each Text.BeforeDelimiter(Text.From([Name], "en-GB"), "_", 1), type text),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Text Before Delimiter",{"Column1"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"DIS", Int64.Type}}),
// Define constants for Ain Al-Abed System (Clarke 1880 ellipsoid)
UTMZone = 40,
a = 6378249.145, // Semi-major axis (Clarke 1880)
f = 1 / 293.465, // Flattening (Clarke 1880),
k0 = 0.9996, // Scale factor
e = Number.Sqrt(2 * f - f * f), // Eccentricity
e1sq = e^2 / (1 - e^2), // Secondary eccentricity squared
// Define the central meridian for the UTM zone in radians
CentralMeridian = (UTMZone * 6 - 183) * Number.PI / 180, // UTM Zone 40 central meridian is 39°E
// Convert UTM to Latitude and Longitude
AddLatLong = Table.AddColumn(#"Changed Type1", "LatLong", each
let
Easting = [X] - 500000.0, // Adjust Easting to the origin
Northing = [Y],
NorthernHemisphere = if Northing >= 0 then true else false,
NorthAdjusted = if NorthernHemisphere then Northing else Northing + 10000000.0,
// Calculate meridional arc
M = NorthAdjusted / k0,
// Footpoint latitude calculation
mu = M / (a * (1 - e^2 / 4 - 3 * e^4 / 64 - 5 * e^6 / 256)),
e1 = (1 - Number.Sqrt(1 - e^2)) / (1 + Number.Sqrt(1 - e^2)),
phi1Rad = mu +
(3 * e1 / 2 - 27 * e1^3 / 32) * Number.Sin(2 * mu) +
(21 * e1^2 / 16 - 55 * e1^4 / 32) * Number.Sin(4 * mu) +
(151 * e1^3 / 96) * Number.Sin(6 * mu),
N1 = a / Number.Sqrt(1 - e^2 * Number.Sin(phi1Rad)^2),
T1 = Number.Tan(phi1Rad)^2,
C1 = e1sq * Number.Cos(phi1Rad)^2,
R1 = a * (1 - e^2) / ((1 - e^2 * Number.Sin(phi1Rad)^2)^1.5),
D = Easting / (N1 * k0),
// Latitude in radians
LatRad = phi1Rad -
(N1 * Number.Tan(phi1Rad) / R1) *
(D^2 / 2 -
(5 + 3 * T1 + 10 * C1 - 4 * C1^2 - 9 * e1sq) * D^4 / 24 +
(61 + 90 * T1 + 298 * C1 + 45 * T1^2 - 252 * e1sq - 3 * C1^2) * D^6 / 720),
// Longitude in radians
LongRad = CentralMeridian +
(D - (1 + 2 * T1 + C1) * D^3 / 6 +
(5 - 2 * C1 + 28 * T1 - 3 * C1^2 + 8 * e1sq + 24 * T1^2) * D^5 / 120) / Number.Cos(phi1Rad),
// Convert to degrees
Latitude = LatRad * 180 / Number.PI,
Longitude = LongRad * 180 / Number.PI
in
[Latitude = Latitude, Longitude = Longitude]
),
// Expand the calculated columns
ExpandLatLong = Table.ExpandRecordColumn(AddLatLong, "LatLong", {"Latitude", "Longitude"})
in
ExpandLatLong
Solved! Go to Solution.
Hi @samahiji ,
Thanks for reaching out in Microsoft Community Forum
After reviewing the query, we identified some syntax errors. As suggested by @OwenAuger , please replace ^ with Number.Power(e,2). Please follow the M query below to resolve your issue.
let
Source = Excel.Workbook(File.Contents("C:\Area.xlsx"), null, true),
Area_All_X_Y_Table = Source{[Item="Area_All_X_Y",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Area_All_X_Y_Table,{{"X", Int64.Type}, {"Y", Int64.Type}, {"DIS", type number}, {"Offset Well", type text}, {"Name", type text}, {"Column1", Int64.Type}}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Area", each Text.BeforeDelimiter(Text.From([Name], "en-GB"), "_", 1), type text),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Text Before Delimiter",{"Column1"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"DIS", Int64.Type}}),
// Define constants for Ain Al-Abed System (Clarke 1880 ellipsoid)
UTMZone = 40,
a = 6378249.145, // Semi-major axis (Clarke 1880)
f = 1 / 293.465, // Flattening (Clarke 1880)
k0 = 0.9996, // Scale factor
e = Number.Sqrt(2 * f - f * f), // Eccentricity
e1sq = Number.Power(e, 2) / (1 - Number.Power(e, 2)), // Secondary eccentricity squared
// Define the central meridian for the UTM zone in radians
CentralMeridian = (UTMZone * 6 - 183) * Number.PI / 180, // UTM Zone 40 central meridian is 39°E
// Convert UTM to Latitude and Longitude
AddLatLong = Table.AddColumn(#"Changed Type1", "LatLong", each
let
Easting = [X] - 500000.0, // Adjust Easting to the origin
Northing = [Y],
NorthernHemisphere = if Northing >= 0 then true else false,
NorthAdjusted = if NorthernHemisphere then Northing else Northing + 10000000.0,
// Calculate meridional arc
M = NorthAdjusted / k0,
// Footpoint latitude calculation
mu = M / (a * (1 - Number.Power(e, 2) / 4 - 3 * Number.Power(e, 4) / 64 - 5 * Number.Power(e, 6) / 256)),
e1 = (1 - Number.Sqrt(1 - Number.Power(e, 2))) / (1 + Number.Sqrt(1 - Number.Power(e, 2))),
phi1Rad = mu +
(3 * e1 / 2 - 27 * Number.Power(e1, 3) / 32) * Number.Sin(2 * mu) +
(21 * Number.Power(e1, 2) / 16 - 55 * Number.Power(e1, 4) / 32) * Number.Sin(4 * mu) +
(151 * Number.Power(e1, 3) / 96) * Number.Sin(6 * mu),
N1 = a / Number.Sqrt(1 - Number.Power(e, 2) * Number.Power(Number.Sin(phi1Rad), 2)),
T1 = Number.Power(Number.Tan(phi1Rad), 2),
C1 = e1sq * Number.Power(Number.Cos(phi1Rad), 2),
R1 = a * (1 - Number.Power(e, 2)) / (Number.Power(1 - Number.Power(e, 2) * Number.Power(Number.Sin(phi1Rad), 2), 1.5))),
D = Easting / (N1 * k0),
// Latitude in radians
LatRad = phi1Rad -
(N1 * Number.Tan(phi1Rad) / R1) *
(Number.Power(D, 2) / 2 -
(5 + 3 * T1 + 10 * C1 - 4 * Number.Power(C1, 2) - 9 * e1sq) * Number.Power(D, 4) / 24 +
(61 + 90 * T1 + 298 * C1 + 45 * Number.Power(T1, 2) - 252 * e1sq - 3 * Number.Power(C1, 2)) * Number.Power(D, 6) / 720),
// Longitude in radians
LongRad = CentralMeridian +
(D - (1 + 2 * T1 + C1) * Number.Power(D, 3) / 6 +
(5 - 2 * C1 + 28 * T1 - 3 * Number.Power(C1, 2) + 8 * e1sq + 24 * Number.Power(T1, 2)) * Number.Power(D, 5) / 120) / Number.Cos(phi1Rad),
// Convert to degrees
Latitude = LatRad * 180 / Number.PI,
Longitude = LongRad * 180 / Number.PI
in
[Latitude = Latitude, Longitude = Longitude]
),
// Expand the calculated columns
ExpandLatLong = Table.ExpandRecordColumn(AddLatLong, "LatLong", {"Latitude", "Longitude"})
in
ExpandLatLong
If you found this post helpful, please consider marking it as "Accept as Solution" and select "Yes" if it was helpful.help other members find it more easily.
Thanks,
Pavan.
Hi @samahiji,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Thank you,
Pavan.
Hi @samahiji,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Thank you,
Pavan.
Hi @samahiji,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Thank you,
Pavan.
Hi @samahiji ,
Thanks for reaching out in Microsoft Community Forum
After reviewing the query, we identified some syntax errors. As suggested by @OwenAuger , please replace ^ with Number.Power(e,2). Please follow the M query below to resolve your issue.
let
Source = Excel.Workbook(File.Contents("C:\Area.xlsx"), null, true),
Area_All_X_Y_Table = Source{[Item="Area_All_X_Y",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Area_All_X_Y_Table,{{"X", Int64.Type}, {"Y", Int64.Type}, {"DIS", type number}, {"Offset Well", type text}, {"Name", type text}, {"Column1", Int64.Type}}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Area", each Text.BeforeDelimiter(Text.From([Name], "en-GB"), "_", 1), type text),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Text Before Delimiter",{"Column1"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"DIS", Int64.Type}}),
// Define constants for Ain Al-Abed System (Clarke 1880 ellipsoid)
UTMZone = 40,
a = 6378249.145, // Semi-major axis (Clarke 1880)
f = 1 / 293.465, // Flattening (Clarke 1880)
k0 = 0.9996, // Scale factor
e = Number.Sqrt(2 * f - f * f), // Eccentricity
e1sq = Number.Power(e, 2) / (1 - Number.Power(e, 2)), // Secondary eccentricity squared
// Define the central meridian for the UTM zone in radians
CentralMeridian = (UTMZone * 6 - 183) * Number.PI / 180, // UTM Zone 40 central meridian is 39°E
// Convert UTM to Latitude and Longitude
AddLatLong = Table.AddColumn(#"Changed Type1", "LatLong", each
let
Easting = [X] - 500000.0, // Adjust Easting to the origin
Northing = [Y],
NorthernHemisphere = if Northing >= 0 then true else false,
NorthAdjusted = if NorthernHemisphere then Northing else Northing + 10000000.0,
// Calculate meridional arc
M = NorthAdjusted / k0,
// Footpoint latitude calculation
mu = M / (a * (1 - Number.Power(e, 2) / 4 - 3 * Number.Power(e, 4) / 64 - 5 * Number.Power(e, 6) / 256)),
e1 = (1 - Number.Sqrt(1 - Number.Power(e, 2))) / (1 + Number.Sqrt(1 - Number.Power(e, 2))),
phi1Rad = mu +
(3 * e1 / 2 - 27 * Number.Power(e1, 3) / 32) * Number.Sin(2 * mu) +
(21 * Number.Power(e1, 2) / 16 - 55 * Number.Power(e1, 4) / 32) * Number.Sin(4 * mu) +
(151 * Number.Power(e1, 3) / 96) * Number.Sin(6 * mu),
N1 = a / Number.Sqrt(1 - Number.Power(e, 2) * Number.Power(Number.Sin(phi1Rad), 2)),
T1 = Number.Power(Number.Tan(phi1Rad), 2),
C1 = e1sq * Number.Power(Number.Cos(phi1Rad), 2),
R1 = a * (1 - Number.Power(e, 2)) / (Number.Power(1 - Number.Power(e, 2) * Number.Power(Number.Sin(phi1Rad), 2), 1.5))),
D = Easting / (N1 * k0),
// Latitude in radians
LatRad = phi1Rad -
(N1 * Number.Tan(phi1Rad) / R1) *
(Number.Power(D, 2) / 2 -
(5 + 3 * T1 + 10 * C1 - 4 * Number.Power(C1, 2) - 9 * e1sq) * Number.Power(D, 4) / 24 +
(61 + 90 * T1 + 298 * C1 + 45 * Number.Power(T1, 2) - 252 * e1sq - 3 * Number.Power(C1, 2)) * Number.Power(D, 6) / 720),
// Longitude in radians
LongRad = CentralMeridian +
(D - (1 + 2 * T1 + C1) * Number.Power(D, 3) / 6 +
(5 - 2 * C1 + 28 * T1 - 3 * Number.Power(C1, 2) + 8 * e1sq + 24 * Number.Power(T1, 2)) * Number.Power(D, 5) / 120) / Number.Cos(phi1Rad),
// Convert to degrees
Latitude = LatRad * 180 / Number.PI,
Longitude = LongRad * 180 / Number.PI
in
[Latitude = Latitude, Longitude = Longitude]
),
// Expand the calculated columns
ExpandLatLong = Table.ExpandRecordColumn(AddLatLong, "LatLong", {"Latitude", "Longitude"})
in
ExpandLatLong
If you found this post helpful, please consider marking it as "Accept as Solution" and select "Yes" if it was helpful.help other members find it more easily.
Thanks,
Pavan.
Hi @samahiji
The issue appears to be the use of ^ as an exponentiation operator.
The exponentiation operator ^ doesn't exist in the M language. Instead, the function Number.Power is available.
So, for example,
e^2
needs to be changed to
Number.Power(e,2)
etc.
Does the code work after making this correction?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.