let
Source = Excel.CurrentWorkbook(){[Name="Table14"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each Text.RemoveRange([Query],Text.Length([Query])-1))
in
#"Added Custom"
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"
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Avg", type text}}),
#"Inserted First Characters" = Table.AddColumn(#"Changed Type", "Last Character", each Text.End([Avg], 1), type text),
#"Added Custom" = Table.AddColumn(#"Inserted First Characters", "Start", each Text.Start([Avg], Text.Length([Avg])-1))
in
#"Added Custom"
2条答案
按热度按时间qxsslcnc1#
要删除最后一个字符,可以使用
Text.RemoveRange
:要将以
K
或M
结尾的字符串转换为它们的真实的,你可以做一些更复杂的事情:* (注意,我假设K=1000
和M=1000000
是一致的;其它系统具有M=1000
和MM=1000000
。我不知道一个系统,其中K=100000
,但你可以很容易地编辑代码,如果你需要)*如果在输入代码时遇到问题,可以将其作为自定义列添加到现有代码中。请确保将代码中的列标识符更改为代码中引用所显示表的任何列名。可能
[Query.Avg Volume]
例如:
62o28rlo2#
使用以下输入表下方的M代码
扩展到这个