Power Query – Replacing Column Names with spaces in Camel Case Notation
I was working with a table with quite a few columns where the column names were using Camel Case Notation (ThisIsMyColumnName), and I did not want to rename them manually.
I used the following Power Query Code below to let it do the column renaming and putting in the space for me.
Thanks to @Excel_City for assisting me in finding the answer
This is what my table looked like with the Camel Case Notation
I then added the following code below
HeadersChange = Table.TransformColumnNames(#"Previous Step Name", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " "))
The only thing that I changed between different tables was the Previous Step Name, which in my example above was called #”Previous Step Name”
After putting in this step it allowed me to have my column names with the spaces as shown below.
That makes my life a lot easier and working much more efficiently.
Here is a working example of the entire code below.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAeLYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ThisIsMyColumName = _t, ItWouldBeBetterWithSpaces = _t]), #"Previous Step Name" = Table.TransformColumnTypes(Source,{{"ThisIsMyColumName", Int64.Type}, {"ItWouldBeBetterWithSpaces", Int64.Type}}), HeadersChange = Table.TransformColumnNames(#"Previous Step Name", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " ")) in HeadersChange
As always if there are any questions or suggestions please let me know.
You could also use the new Splitter.SplitTextByCharacterTransition
= Table.TransformColumnNames(Source, each Text.Combine(Splitter.SplitTextByCharacterTransition({“a”..”z”}, {“A”..”Z”}) (_), ” “))
That also could work, there are always more than one way to get it working.
Thanks for posting.