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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
scott_hsd
Frequent Visitor

DataFlow Power Query optimisation

I have a query setup in a DataFlow and it takes a fair amount of time. From what I can see most of it is in the Expansion steps, although there is a lot of data. I wanted to know is there any room for improvement on the below steps, can you combine expansions?

 

This is basically working through a paged JSON response and drilling down to what is called the daily data.

 

 

 

let
  // Concatenates the Consumer Key & Consumer Secret and converts to base64
  authKey = "Basic " & Binary.ToText(Text.ToBinary(#"CLIENT_ID" & ":" & #"CLIENT_SECRET"),0),
  url = TOKEN_URL,
  // Uses the POST oauth2/token method to obtain a bearer token
  GetJson = Web.Contents(url,
     [
         Headers = [#"Authorization"=authKey,
                    #"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
         Content = Text.ToBinary("grant_type=client_credentials") 
     ]
 ),
  FormatAsJson = Json.Document(GetJson),
  // Gets token from the Json response
  AccessToken = FormatAsJson[access_token],
  AccessTokenHeader = "bearer " & AccessToken,
  // Uses the GET search method using the bearer token from the previous POST oauth2/token method
  GetJsonQuery = Web.Contents("https://api.primetric.com/beta/assignments/",
     [
         Headers = [#"Authorization"=AccessTokenHeader]
     ]
 ),
  // Loop through all the pages
  Source = Json.Document(GetJsonQuery),
  //ToTable = Record.ToTable(Source),
  //RelativePath = Source[next],
  //#"Split text" = "?page=" & Text.AfterDelimiter(RelativePath, "="),
  Custom1 = List.Generate( () =>
        [ResultRecord = Source],
        each [ResultRecord] <> null,
        each [
            ResultRecord = try Json.Document(Web.Contents("https://api.primetric.com/beta/assignments/"
        //    ResultRecord = try Json.Document(Web.Contents([ResultRecord][next]
        // Commented out as this query wont save in a dataflow with a dynamic URL, you need to uncomment the below for this to work
            ,[
                    RelativePath = "?page=" & Text.AfterDelimiter([ResultRecord][next],"="),
                    Headers = [#"Authorization"=AccessTokenHeader]
             ]
             )) otherwise null
        ]
    ),
  #"Converted to table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
  #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to table", "Column1", {"ResultRecord"}, {"ResultRecord"}),
  #"Expanded ResultRecord" = Table.ExpandRecordColumn(#"Expanded Column1", "ResultRecord", {"results"}, {"results"}),
  #"Expanded results" = Table.ExpandListColumn(#"Expanded ResultRecord", "results"),
  #"Expanded results 2" = Table.ExpandRecordColumn(#"Expanded results", "results", {"uuid", "daily_data"}, {"uuid", "daily_data"}),
  #"Expanded daily_data 1" = Table.ExpandRecordColumn(#"Expanded results 2", "daily_data", {"start", "end", "tracked", "scheduled"}, {"start", "end", "tracked", "scheduled"}),
  #"Expanded tracked 1" = Table.ExpandListColumn(#"Expanded daily_data 1", "tracked"),
  #"Expanded scheduled 1" = Table.ExpandListColumn(#"Expanded tracked 1", "scheduled"),
  #"Changed column type" = Table.TransformColumnTypes(#"Expanded scheduled 1", {{"uuid", type text}, {"start", type date}, {"end", type date}, {"tracked", Int64.Type}, {"scheduled", Int64.Type}}),
  #"Added index" = Table.AddIndexColumn(#"Changed column type", "Index", 3000001, 1, Int64.Type)
in
  #"Added index"

 

 

  

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @scott_hsd 

 

You can combine multiple steps into one step. For example, combine below three steps 

#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to table", "Column1", {"ResultRecord"}, {"ResultRecord"}),
#"Expanded ResultRecord" = Table.ExpandRecordColumn(#"Expanded Column1", "ResultRecord", {"results"}, {"results"}),
#"Expanded results" = Table.ExpandListColumn(#"Expanded ResultRecord", "results"),

into 

#"Expanded results" = Table.ExpandListColumn(Table.ExpandRecordColumn(Table.ExpandRecordColumn(#"Converted to table", "Column1", {"ResultRecord"}, {"ResultRecord"}), "ResultRecord", {"results"}, {"results"}), "results"),

Use the expression after "=" to replace the referenced table name in its next step. But I'm not sure if this would improve the performance. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @scott_hsd 

 

You can combine multiple steps into one step. For example, combine below three steps 

#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to table", "Column1", {"ResultRecord"}, {"ResultRecord"}),
#"Expanded ResultRecord" = Table.ExpandRecordColumn(#"Expanded Column1", "ResultRecord", {"results"}, {"results"}),
#"Expanded results" = Table.ExpandListColumn(#"Expanded ResultRecord", "results"),

into 

#"Expanded results" = Table.ExpandListColumn(Table.ExpandRecordColumn(Table.ExpandRecordColumn(#"Converted to table", "Column1", {"ResultRecord"}, {"ResultRecord"}), "ResultRecord", {"results"}, {"results"}), "results"),

Use the expression after "=" to replace the referenced table name in its next step. But I'm not sure if this would improve the performance. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Thanks I did this and yes you are right, it did not improve the performance at all.

Hi @scott_hsd 

 

I saw below notice on Power BI Support page. Not sure if this is a possible cause of the slow query. 

vjingzhang_0-1655276032872.png

 

Jing

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors