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
Anonymous
Not applicable

Dynamically return all column names

Hi

In power query i have the following which dynamically reads the column names for outputting. Im just wondering if there is a cleaner solution whereby i dont have to transform each column but rather leave it as transform all columns in list. This will allow my source to have more columns than it does at present. Also can it determine the type of each column? Appreciate any help or advice on this as im new to Power BI

 

let
Source = Csv.Document(Web.Contents("http:xxxxx"),[Delimiter=",", Columns=18, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
DynamicNameHeader = Table.ColumnNames (#"Promoted Headers"),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{Table.ColumnNames (#"Promoted Headers"){0}, type text}, {Table.ColumnNames (#"Promoted Headers"){1}, type number}, {Table.ColumnNames (#"Promoted Headers"){2}, type number}, {Table.ColumnNames (#"Promoted Headers"){3}, type number}, {Table.ColumnNames (#"Promoted Headers"){4}, type number}, {Table.ColumnNames (#"Promoted Headers"){5}, type number}, {Table.ColumnNames (#"Promoted Headers"){6}, type number}, {Table.ColumnNames (#"Promoted Headers"){7}, type number}, {Table.ColumnNames (#"Promoted Headers"){8}, type number}, {Table.ColumnNames (#"Promoted Headers"){9}, type number}, {Table.ColumnNames (#"Promoted Headers"){10}, type number}, {Table.ColumnNames (#"Promoted Headers"){11}, type number}, {Table.ColumnNames (#"Promoted Headers"){12}, type number}, {Table.ColumnNames (#"Promoted Headers"){13}, type number}, {Table.ColumnNames (#"Promoted Headers"){14}, type number}, {Table.ColumnNames (#"Promoted Headers"){15}, type number}, {Table.ColumnNames (#"Promoted Headers"){16}, type number}, {Table.ColumnNames (#"Promoted Headers"){17}, type number}})
in
#"Changed Type"

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

 

I hadn't noticed. Try it this way (or a differente combination of text and number :-)):

 

#"Changed Type"=Table.TransformColumnTypes(Source, {DynamicNameHeader{0}, type text}& List.Transform(List.Skip(DynamicNameHeader,1), each {_, type number}))

View solution in original post

Anonymous
Not applicable

Got it!....If i just remove Columns=18, it works then...thanks for your help

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

try to adapt this

 

#"Changed Type"=Table.TransformColumnTypes(youTable, List.Transform(DynamicNameHeader, each {_, type number}))

Anonymous
Not applicable

Thanks ....appears to be fine for all columns except the first one which is text and not a number....any solution. Do we need to specify the type or could it be determined by BI

Anonymous
Not applicable

 

I hadn't noticed. Try it this way (or a differente combination of text and number :-)):

 

#"Changed Type"=Table.TransformColumnTypes(Source, {DynamicNameHeader{0}, type text}& List.Transform(List.Skip(DynamicNameHeader,1), each {_, type number}))

Anonymous
Not applicable

Great thanks your suggestion worked.....one further question....any way to have the number of columns dynamic. at present im expecting 18 but this could change depending on the source. Works fine if my source has less but not sure what would happen if source data had more than 18 columns

 

let
Source = Csv.Document(Web.Contents("xxx"),[Delimiter=",", Columns=18, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
DynamicNameHeader = Table.ColumnNames (#"Promoted Headers"),
#"Changed Type"=Table.TransformColumnTypes(#"Promoted Headers", {DynamicNameHeader{0}, type text}& List.Transform(List.Skip(DynamicNameHeader,1), each {_, type number}))
in
#"Changed Type"

Anonymous
Not applicable

try it:

it should work for any number of columns provided that the first is numerical and the other textual.

perphs.

Anonymous
Not applicable

No it dosnt work....i changed it to expect 8 but 18 was sent in source and only 8 displayed. Only works if the source has actually less than the expected number...in this case the expected columns are just blank

Anonymous
Not applicable

Got it!....If i just remove Columns=18, it works then...thanks for your help

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.

60 days of Data Days Carousel

Data Days 2026

Join Fabric 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.