|
| 1 | +let |
| 2 | + Source = Xml.Document( RawXmlSrc ), |
| 3 | + CleanSource = Table.SelectColumns( Source, {"Name", "Value"} ), |
| 4 | + |
| 5 | + // replace / drill down the current [Value] column |
| 6 | + DrillValue = (source as table) as table => |
| 7 | + Table.ExpandTableColumn( source, "Value", {"Value"}, {"Value"} ), |
| 8 | + |
| 9 | + // drill down replacing [Value] column, expanding [Name], [Value] columns |
| 10 | + DrillPairs = (source as table) as table => |
| 11 | + Table.ExpandTableColumn( source, "Value", {"Name", "Value"}, {"Name", "Value"}), |
| 12 | + |
| 13 | + // convert empty tables to flat nulls. Otherwise leave non-empty tables and non-tables alone |
| 14 | + FlattenEmptyTables = (source as any) as any => |
| 15 | + if not (source is table) then source |
| 16 | + else if Table.IsEmpty( source ) then null else source, |
| 17 | + |
| 18 | + #"Renamed Source" = Table.RenameColumns( CleanSource, { {"Name", "Root Element"} }), |
| 19 | + |
| 20 | + Drill4 = |
| 21 | + DrillValue( DrillValue( DrillValue( DrillValue( #"Renamed Source" ) ) ) ), |
| 22 | + |
| 23 | + Pairs = DrillPairs( Drill4 ), |
| 24 | + |
| 25 | + #"Renamed Columns1" = Table.RenameColumns( Pairs,{{"Name", "Element"}}), |
| 26 | + |
| 27 | + Pairs2 = DrillPairs( #"Renamed Columns1" ), |
| 28 | + |
| 29 | + RemoveEmptyTables = Table.TransformColumns( Pairs2, { {"Value", FlattenEmptyTables, type any} } ), |
| 30 | + |
| 31 | + #"Changed Type" = Table.TransformColumnTypes( RemoveEmptyTables , { |
| 32 | + { "Element", type text }, |
| 33 | + { "Name", type text } |
| 34 | + }) |
| 35 | +in |
| 36 | + #"Changed Type" |
0 commit comments