Forum Discussion
Rename Columns with IF formula
- 8 years ago
Hello Users!
v-ljerr-msftThank you for try to hepl me!
Whene i was try to apply your scenario i don't found solution for me.
But now i got solution!
Because i need rename several columns i entered a new variable.let RenameCol = (parameter1, parameter2) => Table.RenameColumns(parameter1, List.Transform(Table.ColumnNames(parameter1), each {_, if Text.Contains(_, parameter2) then Text.TrimStart(Text.TrimEnd(parameter2)) else _})), Source = Web.Page(File.Contents("example.com\test.html")), Data0 = Source{0}[Data], #"Total" = RenameCol(#"Data0", "Total Payments"), #"Percent" = RenameCol(#"Total", "Percent") in #"Percent"Hope it solution save part of live for somebody.
I found one solution
let
Source = Web.Page(File.Contents("example.com\test.html")),
Data0 = Source{0}[Data],
#"Renamed Columns" = Table.RenameColumns(#"Data0", List.Transform(Table.ColumnNames(Data0), each {_, if Text.Contains(_, "Total") then Text.Replace(_, "NEED SELECT UNKNOWN NAME", "Solved") else Text.Replace(_, " ", "Fail")}))
in
#"Renamed Columns"
But it did not help me completely.
It remains to find the command which allows you to replace any name of the column.
Since I do not know the exact name of the column.
- v-ljerr-msft8 years agoMicrosoft Employee
Hi a1i3n,
Based on my test, the formula below should work in your scenario. :smileyhappy:
let Source = Web.Page(File.Contents("example.com\test.html")), Data0 = Source{0}[Data], #"Get Columns Names" = Table.FromList(List.Select(Table.ColumnNames(Data0),each Text.Contains(_, "Total"))), #"Added Custom" = Table.AddColumn(#"Get Columns Names", "Custom", each Text.Start([Column1],14) ), Rename = Table.RenameColumns(Data0, Record.ToList(Table.ToRecords(#"Added Custom"){0})) in RenameRegards
- a1i3n8 years agoRegular Visitor
Hello Users!
v-ljerr-msftThank you for try to hepl me!
Whene i was try to apply your scenario i don't found solution for me.
But now i got solution!
Because i need rename several columns i entered a new variable.let RenameCol = (parameter1, parameter2) => Table.RenameColumns(parameter1, List.Transform(Table.ColumnNames(parameter1), each {_, if Text.Contains(_, parameter2) then Text.TrimStart(Text.TrimEnd(parameter2)) else _})), Source = Web.Page(File.Contents("example.com\test.html")), Data0 = Source{0}[Data], #"Total" = RenameCol(#"Data0", "Total Payments"), #"Percent" = RenameCol(#"Total", "Percent") in #"Percent"Hope it solution save part of live for somebody.