Forum Discussion
Anonymous
4 years agoNot applicable
Detect number in a text string
I want a true/false statement in Power Query to detect numbers in a text string. 45a- TRUE ab- FALSE 34- TRUE aa46- TRUE
- 4 years ago
Hi Anonymous ,
Text.contails could not work on more then one values, similar error refer:
And change yours to the below:
if Text.Contains([Product], "1") or Text.Contains([Product], "2") or Text.Contains([Product], "3") or Text.Contains([Product], "4") or Text.Contains([Product], "5") or Text.Contains([Product], "6") or Text.Contains([Product], "7") or Text.Contains([Product], "8") or Text.Contains([Product], "9") or Text.Contains([Product], "0") then "True" else "False"Did I answer your question? Mark my post as a solution!
Best RegardsLucien
PaulDBrown
4 years agoCommunity Champion
Well... that link got me to this:
Using
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkw0NlGK1QEykszy8sCs3FwIlZdvCGYkJRlZghmWFklJSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [List = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"List", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Select([List], {"0".."9"})),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type1", "Custom.1", each if [Custom] = null then false else true),
#"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Custom"})
in
#"Removed Columns"
Does that help?
Anonymous
4 years agoNot applicable
I'm sorry but the code is just too complex for me to understand. I find it easier to add a condition with true conditions being every number from 1-9, see below:
However a single line code would be easier to manage. Somtehing like this:
text.Contains([Product], type number)- PaulDBrown4 years agoCommunity Champion
Your conditional column approach does deliver a single line of code (and is way simpler than my suggestion! )
= Table.AddColumn(#"Renamed Columns", "Number?", each if Text.Contains([Product], "1") then true else if Text.Contains([Product], "2") then true else if Text.Contains([Product], "3") then true else if Text.Contains([Product], "4") then true else if Text.Contains([Product], "5") then true else if Text.Contains([Product], "6") then true else if Text.Contains([Product], "7") then true else if Text.Contains([Product], "8") then true else if Text.Contains([Product], "9") then true else if Text.Contains([Product], "0") then true else false)- Anonymous4 years agoNot applicable
However, I can't get the code to work properly, I keep getting an error
- PaulDBrown4 years agoCommunity Champion
It shouldn't return an error. Is the Product column set as type Text?