Forum Discussion
Hamster0406
2 years agoFrequent Visitor
Ignoring error in Table.ExpandTableColumn or auto-replace with null
I am loading 100s of XML files from a folder and Power Query has created a function from the first file that I had loaded. The problem is not all the XML files have similar structure. Some have nodes...
- 2 years ago
Thanks! This could work, but I would rather go with the simple method mentioned by the other poster on Stackoverflow as it would be easy to understand and maintain by anyone other than me.
Thanks again for taking the time to help me.
dufoq3
2 years agoCommunity Champion
Hi Hamster0406, try this - it works with sample, but maybe it won't with real data:
Result
You can delete whole Transform File Group and replace code of your Tally ETL Issue query with this code:
let
Source = Folder.Files("C:\Users\Yashw\OneDrive\Email attachments\Tally ETL Issue\"),
FilteredRows = Table.SelectRows(Source, each ([Extension] = ".xml")),
BinaryToTable = Table.TransformColumns(FilteredRows, {{"Content", Xml.Tables}}),
Ad_Transform = Table.AddColumn(BinaryToTable, "Transform", each
[ t1 = [Content]{1}[Table],
t2 = t1{1}[Table],
t3 = t2{0}[Table],
t4 = t3{0}[Table],
ExpandedColumns = List.Accumulate(Table.ColumnNames(t4), t4,
(s,c)=> try Table.ExpandTableColumn(s, c, Table.ColumnNames(Table.Column(s, c){0}), List.Transform(Table.ColumnNames(Table.Column(s, c){0}), (x)=> c & "|" & x)) otherwise s),
Ad_SourceName = Table.AddColumn(ExpandedColumns, "SourceName", (x)=> [Name]),
Reordered = Table.ReorderColumns(Ad_SourceName, {"SourceName"} & Table.ColumnNames(ExpandedColumns))
][Reordered], type table),
CombinedAllFiles = Table.Combine(Ad_Transform[Transform])
in
CombinedAllFiles
Hamster0406
2 years agoFrequent Visitor
Thanks! This could work, but I would rather go with the simple method mentioned by the other poster on Stackoverflow as it would be easy to understand and maintain by anyone other than me.
Thanks again for taking the time to help me.