Below is the Power Query Syntax where I wanted to move the characters before the delimiter.

I must give credit to the Power BI Community who got me going with how to solve this. For reference: Solved: Rename all column headers removing part before to … – Microsoft Power BI Community

This is an example of what my column name looked like below.

What I wanted this to look like is Yr-Mth]

Below is the Syntax I used to get this working.

#"Remove characters before [" = Table.RenameColumns( Source, List.Zip( 
                  { 
                    Table.ColumnNames( Source ), 
                    List.Transform(Table.ColumnNames( Source ), each Text.AfterDelimiter( _, "[") ) 
                   } ) )
  • The “Source” above is the previous step name.
  • The only change I had to make was to the delimiter was “[“

This then resulted in the following output on the column name which was what I wanted.

Removing the character after the delimiter

Whilst I got the first part done, I now wanted to do the same to remove a delimiter at the end, so that it looked like this.

What I wanted this to look like is Yr-Mth

Below is the Syntax I used to get this working.

#"Remove characters after ]" = Table.RenameColumns( #"Remove characters before [", List.Zip( 
                  { 
                    Table.ColumnNames( #"Remove characters before [" ), 
                    List.Transform(Table.ColumnNames( #"Remove characters before [" ), each Text.BeforeDelimiter( _, "]") ) 
                   } ) )
  • The “#”Remove characters before [“” above is the previous step name.
  • I then changed it from Text.AfterDelimiter to Text.BeforeDelimiter
  • The only change I had to make was to the delimiter was “]”

This then resulted in the following output on the column name which was what I wanted.

Summary

Thanks for reading and I do hope that you found this useful and would assist you in saving bucket loads of time having to rename columns manually.

Comments and suggestions are always most welcome.