Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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:
Thanks in advance
Solved! Go to Solution.
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
Proud to be a 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
Proud to be a Super User!
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"
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
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 41 | |
| 38 | |
| 36 | |
| 31 | |
| 28 |
| User | Count |
|---|---|
| 129 | |
| 88 | |
| 79 | |
| 68 | |
| 63 |