问题
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