Hi
I have M Code that enables me to refresh data in a Power BI desktop report via an API from a CRM.
However, as soon as I publish the report on Service, I get the message of ‘This dataset includes a dynamic data source. Since dynamic data sources aren’t refreshed in the Power BI service, this dataset won’t be refreshed.’
Just wondering if anyone can see what the issue is in the code below. (And yes, I have tried Chat GPT.)
The CRM allows only 10,000 rows of data through the API at a time so the M code involves paginating which could be the source of the problem.
let
token_path = “/token”,
client_id = “XXXXXX”,
client_secret = “XXXXXX”,
authKey = "Basic " & Binary.ToText(Text.ToBinary(client_id & “:” & client_secret),0),
scope = “exports”,
Token_Response = Json.Document(Web.Contents(“https://xxx.xxxxx.io”,
[
RelativePath = “/token”,
Headers = [
#“Authorization”=authKey,
#“Content-Type”=“application/x-www-form-urlencoded;charset=UTF-8”],
Content = Text.ToBinary(“grant_type=client_credentials”)
]
)
),
token = Token_Response[access_token],
iterations = 5, // Number of iterations
url = “https://xxx.xxxxx.io/api/exports/pbi-tm-reactivations-3?pageSize=10000”,
FnGetOnePage =
(url) as record =>
let
Source = Json.Document(
Web.Contents(
url,
[
Headers=[
#“Authorization” = "Bearer " & token,
#“content-type” = “application/json”
]
]
)
),
data = try Source[result] otherwise null,
nextCursor = try Source[metadata][nextCursor] otherwise null,
resultUid = try Source[metadata][resultUid] otherwise null,
next = “https://xxx.xxxxx.io/api/exports/pbi-tm-reactivations-3?pageSize=10000&cursor=” & nextCursor & “&resultUid=” & resultUid,
res = [Data=data, Next=next]
in
res,
GeneratedList =
List.Generate(
()=>[i=0, res = FnGetOnePage(url)],
each [i]<iterations and [res][Data]<>null,
each [i=[i]+1, res = FnGetOnePage([res][Next])],
each [res][Data]),
#“Converted to Table” = Table.FromList(GeneratedList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#“Expanded Column1” = Table.ExpandListColumn(#“Converted to Table”, “Column1”)
in
#“Expanded Column1”
Any suggestions would be much apprecitated.