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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors