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
Mic1979
Post Partisan
Post Partisan

Change Column name based on a replacement Chart

Hello

 

I am using the following custom function to replace the vlue in my table:

(data, replacements) =>
[
// generates a record with replacements
repl = Function.Invoke(Record.FromList, List.Reverse(Table.ToColumns(replacements))),
C = Table.TransformRows (
data,
(x) => Record.TransformFields (
x,
List.Transform (
Table.ColumnNames(data),
(name) => {name,(x) => Record.FieldOrDefault(repl,x,x)})) ),

result = Table.FromRecords(C)
][result]

 

Parameter replacements is similar to this:

Mic1979_0-1746526218693.png

 

Now I need to follow a similar approach on the Column Name.

How can I change the code above for this new target?

 

Thanks

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Mic1979 

If you're wanting a similar function to rename columns, you could use this:

(data, replacements) =>
// replacements is a two column table
//   Column 1: old name
//   Column 2: new name
[
    replacementsList = Table.ToRows(replacements),
    result = Table.RenameColumns(data,replacementsList,MissingField.Ignore)
][result]

Is this what you were looking for?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @Mic1979 

If you're wanting a similar function to rename columns, you could use this:

(data, replacements) =>
// replacements is a two column table
//   Column 1: old name
//   Column 2: new name
[
    replacementsList = Table.ToRows(replacements),
    result = Table.RenameColumns(data,replacementsList,MissingField.Ignore)
][result]

Is this what you were looking for?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

It works. Many thanks

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.

Top Solution Authors