Power BI Expression。错误:无法识别该名称。确保拼写正确

问题描述 投票:0回答:1

首先 - 感谢那些迄今为止帮助编码的人...我希望这是我的代码使用 Autotask API 时遇到的最后一个问题。

语法正在 Power BI 和 Chat GPT 中传递,我认为它应该是这样,但收集分页数据似乎失败了。据我所知,这可能是一个普遍错误,所以我不确定我是否在同一个地方。

我希望我可以让它发挥作用并与自动任务社区分享,这将解锁很多功能。

提前致谢

错误

Expression.Error:无法识别名称“gatherpagingdata”。制作 确保拼写正确。

let
// NB Making calls to multiple instances from the same Power BI Dash can cause problems with authentication
// https://www.youtube.com/watch?v=fstsQMZiHME
// check data source security

    // Common parameters
    //texttoconv = "dddd",
    //text = texttoconv as text,
    queryStringApiIntegrationCodevar = "xxxx",
    queryStringUserNamevar = "xxxxxx",
    queryStringUserSecretvar = "xxxxx",
    queryStringContentTypevar = "application/json",
    headers = [#"ApiIntegrationCode"=queryStringApiIntegrationCodevar, #"UserName"=queryStringUserNamevar, #"Secret"=queryStringUserSecretvar, #"Content-Type"=queryStringContentTypevar],
    apiUrl = "https://webservices4.autotask.net/ATServicesRest/V1.0/Projects/query",
    apiUrlnew = "https://webservices4.autotask.net/ATServicesRest/V1.0/Projects/query/next",
    searchFilter = "{""filter"":[{""op"":""gte"",""field"":""id"",""value"":""0""}]}",    


//Functions

converturl = (data as text) as text => 
let
    out = Uri.Parts("http://contoso?a=" & Text.Replace(data, "&", "%26"))[Query][a]
in
    out,

gatherpagingdata = (data as list, uri as text) =>
    let
        // Get the Data
       // Replace Percent URL-encoded characters
        nextpagefunc = converturl(uri),
        //nextpagefunctest = try newURIwhatisit(uri) otherwise error uri,
        textBeforePaging = Text.BeforeDelimiter(nextpagefunc, "?paging"),
        textAfterPaging = Text.BetweenDelimiters(nextpagefunc, "paging=", " "),

        newReq = try Json.Document(Web.Contents(textBeforePaging, [Headers=headers, Query=[paging=textAfterPaging]]))[pageDetails][nextPageUrl] otherwise error "Failed to retrieve data from the API Gather",
        newdata = newReq[items],

       // Add that data to rolling aggregate
        updatedData = List.Combine({data, newdata}),

        // Check for the next URL using function
        nextPageUrl = newReq[pageDetails][nextPageUrl],

       // If there's no next page of data, return. If there is, call @gather again to get more data
       result = if nextPageUrl <> null then gatherpagingdata(updatedData, nextPageUrl) else updatedData
   in
       result,


//Execute
    //initReq = Json.Document(Web.Contents(apiUrl, headers)),
    initReq = try Json.Document(Web.Contents(apiUrl, [Headers=headers, Query=[search=searchFilter]])) otherwise error "Failed to retrieve data from the API 1st Pass",
    //initReq = try Json.Document(Web.Contents(apiUrl, headers)) otherwise error apiUrl,
    initData = initReq[items],


    //before we call gather(), we want see if its even necesarry. First request returns only one page? Return.
    //outputList = try if initReq[pageDetails][nextPageUrl] = null then initData else gather(initData, BaseURI)otherwise error uri,
    uri = initReq[pageDetails][nextPageUrl],

    // Decode the extracted value 

       // Replace Percent URL-encoded characters
        nextpagefunc = converturl(uri),

    outputList = if initReq[pageDetails][nextPageUrl] = null then 
        initData 
    else 
        gatherpagingdata(initData, uri),
    //then place records into a table. This will expand all columns available in the record.
    expand = Table.FromRecords(outputList)
in
    expand
powerbi powerquery data-manipulation powerbi-desktop m
1个回答
0
投票

尝试在递归函数中添加@符号。例如

result = if nextPageUrl <> null then @gatherpagingdata(updatedData, nextPageUrl) else updatedData
© www.soinside.com 2019 - 2024. All rights reserved.