Forum Discussion

silverdale9999's avatar
5 years ago
Solved

Custom Column - Check if all values are present in a string

I have a text field in my data source which contains a number of XML tags.  As part of the data load, this XML is parsed into columns.   The text field is however editable by users in the source sy...
  • Jimmy801's avatar
    5 years ago

    Hello silverdale9999 

     

    here a good solution. Use a combination of List.AllTrue, List.Transform and Text.Contains. The step TagsToBeCheck hold the list with all your tags to be search. This is list is then transformed by checking every list content if its present in your text string

    Check out the solution

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVijJLMlJVUhOSVUoyVfITVXILFYoyUgsUSjILy7OTMpJVYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Tag = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Tag", type text}}),
        TagsToBeCheck= {"me", "that", "possible"},
        Add = Table.AddColumn
        (
            #"Changed Type",
            "Check",
            (add)=> List.AllTrue(List.Transform(TagsToBeCheck, each Text.Contains(Text.Upper(add[Tag]), Text.Upper(_))))
        )
    in
        Add

     

    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