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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.