Last active
January 20, 2020 16:10
-
-
Save Hugoberry/f1d03b632e895b1d455603dda36201c5 to your computer and use it in GitHub Desktop.
[Power Query] return the table at the end of the path eg. xmlPath(XML,{"auditfile","customersSuppliers","customerSupplier"})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(xml as table, path as list)=> | |
let | |
isEmptyTable = each Type.Is(Value.Type(_), Table.Type) and List.Count(Table.ToRows(_))=0, | |
xmlRow2record = (rec, row) => Record.AddField(rec,row{0},if isEmptyTable(row{2}) then null else row{2}), | |
xmlTableExpandNode = (xmlTable, node) => List.Accumulate(Table.SelectRows(xmlTable, each [Name] = node)[Value],#table(1,{}),(s,c)=>s&c), | |
head = List.RemoveLastN(path,1), | |
tail = List.Last(path), | |
exceptTail = List.Accumulate(head,xml,xmlTableExpandNode), | |
tailRecords= List.Transform(Table.SelectRows(exceptTail, each [Name]=tail)[Value],each List.Accumulate(Table.ToRows(_),[],xmlRow2record)), | |
out = Table.FromRecords(tailRecords) | |
in | |
out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment