I have the input data COL1 as shown below that has fields with their values. Some pairs fields/values are separated by = and others appear in table format but separated by text. I'm trying to get 2 columns as output, one with the fields and the other the corresponding values. For the rows containing =, the fields/values are in the same row but the values in "table format" only have their fields (headers=COUNTRY,CAPITAL,POPULATION,LANGUAGE) in first row before the values.
This is the input column and current output I have so far:
This is the desired output I'm trying to get that is like what "unpivot" would do with other kind of input:
This is my current code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lVDJcoQgEP0Vy3MO6sRlKpVDCx0kakOxHCbWVP7/L4KoI5mcwoV6zVuatyw5U+QkIbnsPUNvlMb8/rLkNwQTJlVRVREz5cmZW3YeBlo6mHaklfYTOKloRROQ8CA2K/aFbPg2qH0/SRbJBoTHw6gs6ktdFMVuu7KjjiPNYMY0MmxHQ/CNIU1Zvj5kGQeSdhP2OAnp50TYG28tTnYPLNNA7h0b3j4MUrgEmhkougyeBPz6ce85aLRuQ9dL257xG1vu2rRUsBISk+yp3vLP2/+qfirbDSDDgCdbh+dRHTU2dd1259rZyo9CSVwRprt+wgjGHbi6dl3RnMoHP/z4/gM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [COL1 = _t]),
DeleteMultiSpaces = Table.TransformColumns(Source, {{"COL1", each Text.Combine(List.Select(Text.SplitAny(_, " "), each _ <> "")," "), type text}}),
AddAtSignAsSeparator = Table.ReplaceValue(
Table.ReplaceValue(DeleteMultiSpaces," = ","@",Replacer.ReplaceText,{"COL1"})
," ","@",Replacer.ReplaceText,{"COL1"}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(AddAtSignAsSeparator, {{"COL1", Splitter.SplitTextByDelimiter("@", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "COL1")
in
#"Split Column by Delimiter"


