Forum Discussion
Mcode: Custom Column- Evaluate IF Text Column has Number Value
- 5 years ago
Hello Anonymous
you can add a custom column with this formula (you have to replace "Column1" with your real column name)
if List.AllTrue(List.Transform(Text.ToList([Column1]), each try Value.Is(Number.From(_), type number) otherwise false)) then "numeric" else "alpha numeric"Here the complete code example
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRUitWJVjI2BlNRUWDKACIIlXN2hshBeJaWECUGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if List.AllTrue(List.Transform(Text.ToList([Column1]), each try Value.Is(Number.From(_), type number) otherwise false)) then "numeric" else "alpha numeric") in #"Added Custom"Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hi Anonymous
So you don't need to verify if there are only 2 digits? It can only be 2 digits or sample like AA and A1? Do you have more than 2 digits or letters you need to take care?
And your question towards Jimmy801 solution, you need to paste all the code in Advanced Editor with a blank query, then you can see it all in one query.
Hello Anonymous , Yes only two digits. Sorry I am really new to Mcode, when you say Advanced Editor you mean Add Column > Custom Column right?
BTW Vera, not sure why my results is always a table when I try your code.
Thank you for you responses! 🙂