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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Fcoatis
Post Patron
Post Patron

PowerQuery rename columns by position inside a column with tables

Hello all,

 

Need help here. I´m trying to rename Columns by position, but my tables are inside a column. Here´s what I´m trying to do:

 

Fig1.png

Thanks in advance

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Fcoatis 

Use Table.ColumnNames to access the column name, referenced by position:

 

Table.RenameColumns
(
   [Limpa],
   {
   {Table.ColumnNames([Limpa]){0},"Col1"},
   {Table.ColumnNames([Limpa]){1},"Col2"},
   {Table.ColumnNames([Limpa]){2},"Col3"},
   {Table.ColumnNames([Limpa]){3},"Col4"}
   }
)

 

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

3 REPLIES 3
PhilipTreacy
Super User
Super User

Hi @Fcoatis 

Use Table.ColumnNames to access the column name, referenced by position:

 

Table.RenameColumns
(
   [Limpa],
   {
   {Table.ColumnNames([Limpa]){0},"Col1"},
   {Table.ColumnNames([Limpa]){1},"Col2"},
   {Table.ColumnNames([Limpa]){2},"Col3"},
   {Table.ColumnNames([Limpa]){3},"Col4"}
   }
)

 

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


@PhilipTreacy Thank you very much!!! It worked.

Thanks @PhilipTreacy  - that's heaps more efficient than the custom function I was working on. Looks something like this:

 

 

= (Parameter1 as binary) => let
Source = Csv.Document(Parameter1,[Delimiter=",", Columns=6, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Demoted Headers" = Table.DemoteHeaders(#"Promoted Headers"),
#"Kept First Rows" = Table.FirstN(#"Demoted Headers",1),
#"Transposed Table" = Table.Transpose(#"Kept First Rows"),
#"Added Index" = Table.AddIndexColumn(#"Transposed Table", "Index", 1, 1, Int64.Type),
#"Added Conditional Column" = Table.AddColumn(#"Added Index", "New Headings", each if [Index] = 1 then "Col1" else if [Index] = 2 then "Col2" else if [Index] = 3 then "Col3" else [Index]),
#"Removed Other Columns" = Table.SelectColumns(#"Added Conditional Column",{"New Headings"}),
#"Transposed Table1" = Table.Transpose(#"Removed Other Columns"),
#"Appended Query" = Table.Combine({#"Transposed Table1", #"Demoted Headers"}),
#"Promoted Headers1" = Table.PromoteHeaders(#"Appended Query", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers1",{{"Col1", type text}, {"Col2", type text}, {"Col3", type text}, {"4", type text}, {"5", type text}, {"6", type text}}),
#"Removed Top Rows" = Table.Skip(#"Changed Type",1)
in
#"Removed Top Rows"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.