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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dkpcr5
Helper II
Helper II

Dynamic table headers from API

Hi all,

 

I need help dynamically pulling headers when importing data via API in PowerQuery. I'm currently entering headers manually, which is terribly inefficient and requires manual updates whenever new fields are added to the API.

 

Here's what I have:

let

    endpoint = "(REST API endpoint URL)",
    directive= "A",
    cache    = "false",
    command  = Record.FromList({keys})  ,
    headers  = Record.FromList({command},{"Headers"}),
    payload  = Json.Document(Web.Contents(endpoint, headers)),
    value = payload[value],
    #"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {
"Header 1",
"Header 2",
"Header 3"        
})
 
in

    #"Expanded Column1"

In this query's current state, only the identified headers ("Header 1", "Header 2", "Header 3") are pulled into the table.

 

What I'd rather say is, "Give me every column from all headers available." That way, when I refresh the dataset, any new columns will be pulled dynamically.

 

Any help would be appreciated. Thanks!

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", Headers)

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", Headers)

It worked. Thanks so much!

Anonymous
Not applicable

I have a question. How did you define key?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors