Power BI M语言报token comma expected 密钥波浪号位置语法错误
Power BI M函数调用必应地图路线接口报「应为逗号标记」语法错误
问题表现
在Power BI中编写调用必应地图REST v1路线接口的M语言自定义函数时,运行抛出语法错误,原始完整代码如下:
(LatStart as text, LonStart as text, LatDest as text, LonDest as text)=> let Source = Xml.Tables(Web.Contents("https://dev.virtualearth.net/REST/v1/Routes/", [ RelativePath="DistanceMatrix", Query =[ origins="" & LatStart & "," & LonStart &"", destinations="" & LatDest & "," & LonDest & "", travelMode="driving", distanceUnit="km", timeUnit="minute", o="xml", key=gu9tL5NeUo6CsNKZWj00~o05Bp1GQ76ISmSrxiptgBQ~AoBvsa-SMlEHUcZuCl6tIVBRbDZDq0QDBuZBdpNfTUao5AzK3ua-pwaBl1AcwiPu ] ] )), #"Geänderter Typ" = Table.TransformColumnTypes(Quelle,{{"Copyright", type text}, {"BrandLogoUri", type text}, {"StatusCode", Int64.Type}, {"StatusDescription", type text}, {"AuthenticationResultCode", type text}, {"TraceId", type text}}), ResourceSets = #"Geänderter Typ"{0}[ResourceSets], ResourceSet = ResourceSets{0}[ResourceSet], #"Geänderter Typ1" = Table.TransformColumnTypes(ResourceSet,{{"EstimatedTotal", Int64.Type}}), Resources = #"Geänderter Typ1"{0}[Resources], Resource = Resources{0}[Resource], Results = Resource{0}[Results], Distance = Results{0}[Distance], #"Geänderter Typ2" = Table.TransformColumnTypes(Distance,{{"OriginIndex", Int64.Type}, {"DestinationIndex", Int64.Type}, {"TravelDistance", Int64.Type}, {"TravelDuration", Int64.Type}, {"TotalWalkDuration", Int64.Type}}) in #"Geänderter Typ2"
Power BI返回错误提示:token comma expected(应为逗号标记),错误定位在key=对应取值的第一个~符号位置,报错片段如下:
key=gu9tL5NeUo6CsNKZWj00~o05Bp1GQ76ISmSrxiptgBQ~AoBvsa-SMlEHUcZuCl6tIVBRbDZDq0QDBuZBdpNfTUao5AzK3ua-pwaBl1AcwiPu
错误原因
- 核心语法错误:M语言中记录结构的文本类型值必须用双引号包裹,代码里
key参数后的必应密钥是文本值,但未加双引号,解析器会将无引号内容识别为标识符或运算表达式,把值内的~判定为运算符,无法解析Query记录的结构,最终抛出缺少逗号的错误。 - 隐性运行错误:代码中
#"Geänderter Typ"步骤引用了不存在的Quelle对象,这是德语版Power BI生成步骤时的默认源表名,和前序定义的Source步骤名不匹配,修复语法错误后会触发「名称Quelle不存在」的运行时报错。
修复方法
- 给
key=后的密钥字符串首尾加上双引号,明确标记为文本类型 - 将
#"Geänderter Typ"步骤中Table.TransformColumnTypes的第一个参数从Quelle修改为前序步骤名Source
修复后key参数的正确写法:
key="gu9tL5NeUo6CsNKZWj00~o05Bp1GQ76ISmSrxiptgBQ~AoBvsa-SMlEHUcZuCl6tIVBRbDZDq0QDBuZBdpNfTUao5AzK3ua-pwaBl1AcwiPu"
内容的提问来源于stack exchange,提问作者Sithys
相关产品推荐
相关产品推荐

