Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sesame5486
Frequent Visitor

Power Query only refreshes after refreshing preview

I'm using Power Query in Excel. I've created a query to extract data from Anaplan via APIs. The query works, but I can't refresh normally.

 

Using Refresh All triggers a query refresh, but the actual data is not updated. If I edit the query, refresh the preview of the first step  (the authentication step) and close and load, the data updates.

 

For some reason, Power Query is re-using the old value of the first step for authentication (in other words, the old authentication token). How do I force Power Query to refresh all the steps in my query?

 

let
// Get a new authentication token.
mytoken1 = (let
auth_key = "Basic " & GetValue("Encoded_Auth"),
url = "https://auth.anaplan.com/token/authenticate",
header = [#"Authorization" = auth_key,
#"Content-Type" = "application/json"],
webdata1 = Web.Contents(url, [Headers=header,Content= Text.ToBinary("")]),
response1 = Json.Document(webdata1),
tokenInfo = "AnaplanAuthToken " & response1[tokenInfo][tokenValue]
in
tokenInfo),

// Trigger data download in model.
#"WorkspaceID" = GetValue("WorkspaceID"),
#"ModelID" = GetValue("ModelID"),
#"ExportID" = GetValue("ExportID_Movement"),
#"auth_key2" = mytoken1,
url2 = "https://api.anaplan.com/2/0/workspaces/" & #"WorkspaceID" & "/models/" & #"ModelID" & "/exports/" & #"ExportID" & "/tasks",
header2 = [#"Authorization" = #"auth_key2",
#"Content-Type" = "application/json"],
content2 = "
{
""localeName"" : ""en_US""
}
",
webdata2 = Web.Contents(url2, [Headers=header2, Content= Text.ToBinary(content2)]),
response2 = Json.Document(webdata2),

// Check column count when downloading file.
// Pause and then download data from model.
Stop1 = () => Csv.Document(Web.Contents("https://api.anaplan.com/2/0/workspaces/" & #"WorkspaceID" & "/models/" & #"ModelID" & "/files/" & #"ExportID" & "/", [Headers=[Authorization=#"auth_key2", #"Content-Type"="application/csv; charset=UTF-8", Accept="application/octet-stream"]]),[Delimiter=",", Columns=16, Encoding=65001, QuoteStyle=QuoteStyle.None]),
Source = Function.InvokeAfter(Stop1, #duration(0,0,0,10)),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),

// Stop here when copying query.

#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"L3# Deals: Active", type text}, {"L3# Deals: Active: Code", type text}, {"L3# Deals: Active: Asset Class", type text}, {"L3# Deals: Active: LOB", type text}, {"L3# Deals: Active: Product Type", type text}, {"L3# Deals: Active: Product Sub Type", type text}, {"Client Fee Types", type text}, {"Fundraising Teams", type text}, {"Sources", type text}, {"Investor Types", type text}, {"Time", type date}, {"Year", type text}, {"NCY Fundraising (Excl. Confirmations)", Currency.Type}, {"NCY Confirmed Only", Currency.Type}, {"NCY Fundraising (Incl. Confirmations)", Currency.Type}, {"USD Fundraising (Excl. Confirmations)", Currency.Type}})

in
#"Changed Type"

 

1 ACCEPTED SOLUTION
sesame5486
Frequent Visitor

I solved the issue, but it raises another question!

 

The process to download data from Anaplan is as follows:

  1. Authenticate and get an authentication token. This is used in future API requests.
  2. Trigger the download process in Anaplan. This only starts the download on the server side. No data is sent to Power Query.
  3. Download the data (from step 2).
  4. Transform data as required.

 

Step 2 above is represented by this line:

response2 = Json.Document(webdata2),

This line is then no longer used in the query. All this does is start the download process on the server side, it is not used again in the query. Because it is not used, I don't think Power Query bothers to run it when refreshing the query. Why would it? The line doesn't impact the query. BUT, from an API perspective, I need this to be updated each time.

 

This is why refreshing the preview worked, it forced Power Query to update this value and hence re-trigger the download process.

 

View solution in original post

5 REPLIES 5
sesame5486
Frequent Visitor

I solved the issue, but it raises another question!

 

The process to download data from Anaplan is as follows:

  1. Authenticate and get an authentication token. This is used in future API requests.
  2. Trigger the download process in Anaplan. This only starts the download on the server side. No data is sent to Power Query.
  3. Download the data (from step 2).
  4. Transform data as required.

 

Step 2 above is represented by this line:

response2 = Json.Document(webdata2),

This line is then no longer used in the query. All this does is start the download process on the server side, it is not used again in the query. Because it is not used, I don't think Power Query bothers to run it when refreshing the query. Why would it? The line doesn't impact the query. BUT, from an API perspective, I need this to be updated each time.

 

This is why refreshing the preview worked, it forced Power Query to update this value and hence re-trigger the download process.

 

ppm1
Solution Sage
Solution Sage

That is odd. A quick test I would do would be to copy your mytoken1 into a separate query with a different name, and then reference that query instead.

 

Pat

Microsoft Employee

Agreed weird behaviour. It seems that Power Query is being "lazy" and re-using the old authentication token. I tried this but it didn't work. Tried both as a function and query.

Anonymous
Not applicable

Why not set the auth query to refresh upon opening, and then do the refresh all?

 

--Nate

This didn't resolve the issue unfortunately.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors