Forum Discussion

squiddly's avatar
squiddly
Advocate I
8 years ago
Solved

Expand Column Containing Some Tables

I have a decent sized XML file around 230MB.  The file contains several columns that can themselves contain tables.  See screenshot below.  I regret that I cannot provide even a shortened version of ...
  • squiddly's avatar
    squiddly
    8 years ago

    I was able to understand Marcel's solution after sleeping on it a bit.  Here's the code I used:

     

        #"Expanded cves" = Table.ExpandTableColumn(#"Removed Columns", "cves", {"cve"}, {"cves.cve"}),
        #"Lists from cves" = Table.TransformColumns(#"Expanded cves",{{"cves.cve", each if _ is table then Table.ToList(_) else {_}}}),
        #"Expanded cves.cve" = Table.ExpandListColumn(#"Lists from cves", "cves.cve"),

    #"Expanded cves" step expands the 'cves' column down to the 'cve' column.  The 'cve' column is the one that contains zero or one or multiple values.  If I expand this normally, the column contains values of either null, <single value>, or 'Table'.

     

    #"Lists from cves" performs an if on each value to determine if it's a table.  If it's a table, then it puts that value into a list.  If it's a normal value, it leaves it alone.

     

    #"Expanded cves.cve" expands the lists such that it duplicates rows for each unique value in any tables found in "cve".

     

    I've been able to repeat this to great success.  I'm sorry I can't provide the XML as it's proprietary.  I truly appreciate your effort Dale!