Escape Special Character in Column Name

Veritan

Active Member
Joined
Jun 21, 2016
Messages
383
Hi all, need some syntax help here. I have these 3 lines of M code shown below (they're part of a larger query):

Power Query:
#"Remove % from Load Factor Name" = Table.RenameColumns(#"Merge Periods with Comma",{{"Load Factor%", "Load Factor"}}),
#"Divide Load Factor by 100" = Table.ReplaceValue(#"Remove % from Load Factor Name", each [Load Factor], each [Load Factor]/100, Replacer.ReplaceValue, {"Load Factor"}),
#"Add % back to Load Factor%" = Table.RenameColumns(#"Divide Load Factor by 100",{{"Load Factor", "Load Factor%"}}),

The 1st and 3rd line are basically pointless, I'm only including them because the original data set has a column named "Load Factor%". This data set comes from an external 3rd party and I have no control over their naming conventions. The only line I'm interested in keeping is the 2nd line, which divides the original values by 100. Unfortunately, because of the percent sign in the original column name, I keep getting an "Invalid Identifier" error whenever I try to reference the column "Load Factor%" like this:

Power Query:
#"Divide Load Factor by 100" = Table.ReplaceValue(#"Merge Periods with Comma", each [Load Factor%], each [Load Factor%]/100, Replacer.ReplaceValue, {"Load Factor%"}),

The error is specifically related to when I refer to the parameter "each [Load Factor%]". Can someone provide me with the escape character syntax that would allow me to directly reference the column "Load Factor%" without having to rename it twice just so I can work with it? I've been able to get #(0025) (the Unicode ID for %) to work when just dealing with a string, but not when it's in the square brackets. Thanks in advance.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I don't have your source data, so:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Divided Column" = Table.TransformColumns(Source, {{"Load Factor%", each _ / 100, type number}})
in
    #"Divided Column"
no any errors
 
Upvote 0
Solution
Thanks sandy! That definitely worked. I'm still new to M and hadn't thought to use TransformColumns instead of ReplaceValue. Really appreciate the help.
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,309
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top