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
cflynn_29
Helper I
Helper I

Dynamically Rename 1st Column

I am trying to dynamically rename the 1st column from whatever its Number value is to just "Column1"

 

cflynn_29_1-1674767181216.png

 

From here i use = Table.ColumnNames(#"Promoted Headers") to get the column names as a list.

cflynn_29_2-1674767247492.png

 

From there i only want the first item in the list so i use List.FirstN(Custom1,1)  and that gets me the 1st item which is the first column name

cflynn_29_3-1674767341645.png

 

Now i want to rename that column in the #"Promoted Headers" table/step so i tried

= Table.RenameColumns(#"Promoted Headers", #"Kept First Items", Column1) and this is what i get

 

cflynn_29_4-1674767891990.png

 

Not sure if i am using the function incorrectly some help would be great.

 

And here is the Mcode

#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table5", [PromoteAllScalars=true]),
Custom1 = Table.ColumnNames(#"Promoted Headers"),
#"Kept First Items" = List.FirstN(Custom1,1),
Custom2 = Table.RenameColumns(#"Promoted Headers", #"Kept First Items", Column1),

 

Thank you,

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

Custom2 = Table.RenameColumns(#"Promoted Headers", #"Kept First Items"&{“Column1"})

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

Custom2 = Table.RenameColumns(#"Promoted Headers", #"Kept First Items"&{“Column1"})

ImkeF
Community Champion
Community Champion

Hi @cflynn_29 ,
well done, you are on the right path here. Just put the new name into quotes ("") like so:

 

Custom2 = Table.RenameColumns(#"Promoted Headers", #"Kept First Items", "Column1"),

 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Got a slightly new error here, is it because the original column name is being represented as a number and not a text value?

cflynn_29_0-1674774494373.png

 

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.