How to refresh report that uses custom functions on Power BI Service using functions?

蹲街弑〆低调 提交于 2020-03-04 21:34:37

问题


Can some one please help me convert this code below in the form of functions so that the code is easy to re use instead of hardcoding the URL's to avoid the error for data source which comes in the current code ? This is with reference to a fix in page How to refresh report that uses custom functions on Power BI Service? page which when in tried works but has lot of repetitive code?

BaseUrl = "https://jira.domain.com/rest/api/2/search?jql=project in ('ABC','DEF') AND issuetype = Bug AND createdDate >= startOfMonth(-12)",
SubUrl = BaseUrl & " &expand=projects.issuetypes.fields,version&fields=key,priority,status,created,labels,project,components,versions,fixVersions,affectedVersion,resolution,customfield_45132,customfield_11760,customfield_10937,customfield_13320,customfield_68920,customfield_25833,customfield_47426,reporter,resolutiondate,created,assignee",
JiraIDPerPage = 1000,

GetJson = (Url) =>
    let 
        RawData = Web.Contents(Url),
        Json    = Json.Document(RawData)
    in  Json,

GetJiraIDCount = () =>
    let Url   = BaseUrl & "&maxResults=0",
        Json  = GetJson(Url),
        Count = Json[#"total"]
    in  Count,

GetPage = (Index) =>
    let Skip  = "&startAt=" & Text.From(Index * JiraIDPerPage),
        Top   = "&maxResults=" & Text.From(JiraIDPerPage),
        Url   = SubUrl & Skip & Top,
        Json  = GetJson(Url),
        Value = Json[#"issues"]
    in  Value,

JiraIDCount = List.Max({ JiraIDPerPage, GetJiraIDCount() }),
PageCount   = Number.RoundUp(JiraIDCount / JiraIDPerPage),
PageIndices = { 0 .. PageCount - 1 },
Pages       = List.Transform(PageIndices, each GetPage(_)),
JiraID    = List.Union(Pages),
Table       = Table.FromList(JiraID, Splitter.SplitByNothing(), null, null, ExtraValues.Error),

#"Expanded Column1" = Table.ExpandRecordColumn(#"Table", "Column1", {"expand", "id", "self", "key", "fields"}, {"Column1.expand", "Column1.id", "Column1.self", "Column1.key", "Column1.fields"}) in 
#"Expanded Column1"

来源:https://stackoverflow.com/questions/60052490/how-to-refresh-report-that-uses-custom-functions-on-power-bi-service-using-funct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!