Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Extracting names from html in a column with variable structure

Hi there,   I have connected to a SharePoint List which imports data from a Microsoft Form. When the data is imported it replaces some of the text with HTML code: For Example Appointed Candida...
  • Vijay_A_Verma's avatar
    4 years ago

    Use this in PQ. See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7ZNBT8IwFMe/SsWLJCO2G+u2LB62ITGcjB6BQzcKNJZuaQtRT979ln4SO4cMYRglMVxM1mVt3/vv/359HQ5boyWETjZhK5BxotTVqHX9qKkUhCflvA8DjHEU4wT1u65v+7AbJ37f9mK352McjCoBWsso/cSpkZnmQnemZMH4U7lp43PXDxPCWSqZBSLJCLfADeUrqllGLKCIUB1FJZuGH6mKPdM6EaFCh1nOc1mvyVl6AS1QPu3wqxFVELFxspOWcpI9bOLfXl4HRFBwv2B6XiVfmjKqzdbY+ifURKjM3lZL5fasBngMUOQ4Doy6KHECZID6MXJtL0B+5CXdXuTBPaDHlXWgksPe9w+wgbYdWKAa7TA1v5vJfCkmnaZI1zVh69fu6RxdFYR7daE6dv2FMAwbhH/ld8JUwclW4zLBmemSM7YocqmJ0BtPg3wuvu2eUzM3ISdnZHTBgHH+Q0R/j8RpRHJLzU0FdyRNmT7o7POuj98B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Appointed Candidate(s)" = _t]),
        #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Appointed Candidate(s)", Splitter.SplitTextByDelimiter("</", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Appointed Candidate(s)"),
        #"Inserted Text After Delimiter" = Table.AddColumn(#"Split Column by Delimiter", "Text After Delimiter", each Text.AfterDelimiter([#"Appointed Candidate(s)"], ">", {0, RelativePosition.FromEnd}), type text),
        #"Added Custom" = Table.AddColumn(#"Inserted Text After Delimiter", "Extracted Name", each Text.Select([Text After Delimiter],{"a".."z","A".."Z"," "})),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Text After Delimiter"}),
        #"Filtered Rows1" = Table.SelectRows(#"Removed Columns", each ([Extracted Name] <> ""))
    in
        #"Filtered Rows1"