我正在嘗試在 M 中撰寫一個自定義列來檢測該欄位是否包含一個 5 位數字,然后將該 5 位數字提取到一個新列中。當員工產生費用時,如果是作業,他們需要指定作業編號。如果沒有,他們通常會輸入文本。
IF text.contains number like "#####" 然后讓新列具有該 5 位數字,否則為 null。
我在如何用 M 寫字方面遇到了難以置信的困難。我試著在
uj5u.com熱心網友回復:
假設您的資料在 [Column1] 列中,然后嘗試
添加列..自定義列...使用公式:
= try if Number.From([Column1])>0 and Text.Length(Text.From([Column1]))=5 then [Column1] else null otherwise null
尋找 Column1 是可以評估為數字的東西,并且當被視為字串時長度為 5 個字符,否則為空。這允許像 '01234 這樣的前導零,但不會嘗試考慮混合文本/數字,例如 A12345

如果您需要洗掉 alpha,請嘗試
= if Text.Length(Text.Select(Text.From([Column1]),{"0".."9"}))=5 then Text.Select(Text.From([Column1]),{"0".."9"}) else null

uj5u.com熱心網友回復:
鑒于您所寫的內容,有效條目將在 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://www.uj5u.com/shujuku/409588.html
標籤:
