Home > Mobile >  Check if first character of text contains a value from a list
Check if first character of text contains a value from a list

Time:07-27

I am trying to identify if the first character within my source data is either Uppercase or starts with a number and if so return |.

For some reason, my code only returns this if the row starts uppercase and not if a value is present despite being included in the list to search for. I do not wish to have another query as my list but rather just state the list here if possible.

enter image description here

Note how 2.0. SUBHEADING does not return with |

M code:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Merged", type text}}),
    #"Added Custom4" = Table.AddColumn(#"Changed Type", "Custom.2", each if List.Count(Splitter.SplitTextByAnyDelimiter( {"a".."z","0".."9"} ) (Text.Start([Merged], 1))) > 1 then " " else "| ")
in
    #"Added Custom4"

Data

SUBHEADING 1
Non-sensical
sentence 1. Sentence 2.
Sentence 3 part 3a,
part 3b, and
part 3c.
SUBHEADING 1.1.
Non-sensical
sentence 4. Sentence 5.
Sentence 6 part 3a,
part 3b, 3c and
3d.
2.0. SUBHEADING
Extra Info 1 (Not a proper sentence)
Extra Info 2
Sentence 7.
SUBHEADING 3.0
Sentence 8.

CodePudding user response:

#"Added Custom4"  = Table.AddColumn(#"Changed Type", "Custom", each try if Text.PositionOfAny(Text.Start(Text.From([Merged]),1), {"A".."Z","0".."9"}) = 0 then "|" else null otherwise null)

note Im using a null and a pipe. Your code was using a blank string and a pipe/space

  • Related