cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
a1i3n
Regular Visitor

Rename Columns with IF formula

Hello Users!

I try to getin data from dynamic update HTML file. And every time column name contains unique names with constant value.
Somthing like this "Total payments 12324.00" or "Total payments 43567.00"
Last numbers in column name, it summ of column.
So for workin with data of table i need rename columns for get direct names.

So i try to make formula by my self and it dasnt work for me.

 

"#"Rename Columns" = Table.RenameColumns(Source, if([ColumnName]=(Text.Contains("Total Payments")), then {{[ColumnName], "Total Payments"}} else [ColumnName]))

I wery poor in Power Query. Please save my time.

1 ACCEPTED SOLUTION

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.

View solution in original post

3 REPLIES 3
a1i3n
Regular Visitor

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.

Hi @a1i3n,

 

Based on my test, the formula below should work in your scenario. Smiley Happy

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
    Rename

 

Regards

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.

View solution in original post

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Kudoed Authors