我想删除该列的最后一个字符,K并且M。这样我就可以添加另一列,如果最后一个字符是M数字 x 1000000,否则是数字 x 100000。我能做什么?
下面的屏幕截图是已应用于表的步骤:
要删除最后一个字符,您可以使用Text.RemoveRange:
let
Source = Excel.CurrentWorkbook(){[Name="Table14"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each Text.RemoveRange([Query],Text.Length([Query])-1))
in
#"Added Custom"
Run Code Online (Sandbox Code Playgroud)
K要将以实数结尾的字符串转换M为实数,您可以做一些更复杂的事情:( 请注意,我假设K=1000和M=1000000保持一致;其他系统有M=1000和MM=1000000。我不知道有哪个系统K=100000,但您可以轻松编辑代码如果你需要)
let
Source = Excel.CurrentWorkbook(){[Name="Table14"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Query", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each
let
x = Text.End([Query],1),
y = Number.From(Text.RemoveRange([Query],Text.Length([Query])-1)),
result = if x = "K" then y * 1000
else if x = "M" then y * 1000000
/*Note that code assumes that if string doesn't end with K or M
it is a number. You may want to test specifically for that to avoid errors*/
else Number.From([Query])
in
result, type number)
in
#"Added Custom"
Run Code Online (Sandbox Code Playgroud)
如果您在输入代码时遇到问题,可以将其作为自定义列添加到现有代码中。请务必将代码中的列标识符更改为代码中引用您显示的表的列名称。可能[Query.Avg Volume]
例如: