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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Dynamic Column Names

I have a Web API endpoint which I want to pull data from it. It is protected with OAuth2.
Right now I can successfully pull the data from it but I have to specify the column names.
I want the column names to be dynamic.


The below code is working good:

let
GetAuth = Web.Contents("https://localhost/token",
[
Headers = [#"Accept"="application/json",
#"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
Content = Text.ToBinary("username=username&password=password&grant_type=password")
]),
FormatAuthAsJson = Json.Document(GetAuth),
access_token = FormatAuthAsJson[access_token],

ReportData = Json.Document(Web.Contents("https://localhost/api/Search",
[
Headers=[Authorization="bearer "&access_token,
#"Content-Type"="application/json; charset=utf-8"]
,Content = Text.ToBinary("{""SearchCriteria"":""test""}")
])),
#"Converted Data To Table" = Table.FromList(ReportData, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Report Data" = Table.ExpandRecordColumn(#"Converted Data To Table", "Column1", { "Id", "Name", "Description" })

in
#"Expanded Report Data"


When I change #"Expanded Report Data" to be like that:
#"Expanded Report Data" = Table.ExpandTableColumn(#"Converted Data To Table", "Column1", List.Union(List.Transform(#"Converted Data To Table"[Column1], each Table.ColumnNames(_))))


I got this error:
Expression.Error: We cannot convert a value of type Record to type Table.

 

 

Any help will be appricaited?

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello

 

substitude this code

#"Converted Data To Table" = Table.FromList(ReportData, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Report Data" = Table.ExpandRecordColumn(#"Converted Data To Table", "Column1", { "Id", "Name", "Description" })

with this one

#"Converted Data To Table" = Table.FromList(ReportData, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
UniqueRecordNames = List.Union( List.Transform(#"Converted Data To Table"[Column1], each  Record.ToTable(_)[Name])),
#"Expanded Report Data" = Table.ExpandRecordColumn(#"Converted Data To Table", "Column1", UniqueRecordNames )

 this should to the trick. Was not able to test your code, but it should work

Have fun

Jimmy

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello

 

substitude this code

#"Converted Data To Table" = Table.FromList(ReportData, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Report Data" = Table.ExpandRecordColumn(#"Converted Data To Table", "Column1", { "Id", "Name", "Description" })

with this one

#"Converted Data To Table" = Table.FromList(ReportData, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
UniqueRecordNames = List.Union( List.Transform(#"Converted Data To Table"[Column1], each  Record.ToTable(_)[Name])),
#"Expanded Report Data" = Table.ExpandRecordColumn(#"Converted Data To Table", "Column1", UniqueRecordNames )

 this should to the trick. Was not able to test your code, but it should work

Have fun

Jimmy

Anonymous
Not applicable

That is perfect @Jimmy801  thanks a million.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.