我试图用M编写一个自定义列,以检测字段是否包含5位数字,然后将该5位数提取到一个新列中。员工发生费用时,他们需要指定职务编号(如果是职务的话)。如果没有,他们通常输入文本。
如果text.contains数字如"#####“,则新列有5位数,否则为null。
我在如何用M写东西上遇到了令人难以置信的困难
发布于 2022-01-12 21:28:34
假设您的数据位于列Column1中,然后尝试
添加列..。定制栏..。公式:
= try if Number.From([Column1])>0 and Text.Length(Text.From([Column1]))=5 then [Column1] else null otherwise null它寻找的是可以计算为一个数字的Column1,如果它的长度为5个字符,则作为一个字符串,否则将为null。这允许像'01234‘这样的前导零,但不试图解释混合文本/数字,如A12345

如果您需要删除alpha,请尝试
= if Text.Length(Text.Select(Text.From([Column1]),{"0".."9"}))=5 then Text.Select(Text.From([Column1]),{"0".."9"}) else null

发布于 2022-01-13 00:34:16
考虑到您所写的内容,有效的条目将在10,000到99,999之间,并且前面可能有一个J,也可能没有,您可以添加一个列来检测它。
//Ensure Column1 (or whatever it's real name is) is of type text and NOT any
#"Added Custom" = Table.AddColumn(#"Previous Step", "Job Number", each
let
x = Text.TrimStart(Text.Upper([Column1]),"J"),
n = try Number.From(x) otherwise 0
in
if n>=10000 and n<100000 then n else null)

https://stackoverflow.com/questions/70688096
复制相似问题