Forum Discussion
cpinho
Advocate I
9 years agoHow to expand all nested tables at once table.expandtablecolumn
Hi guys, I've an issue, when working with getting data from web (html) it is common to have a source with hundred or more nested tables. How can i expand it all at once? I've seen a code from...
- 9 years ago
The code below expands all nested tables from this webpage (as an example) as requested, but I'm note sure if the result makes much sense.
It includes an embedded recursive function fnCombineAll.Possibly some further refinement would be required, but at least we have a start.
let Source = Web.Page(Web.Contents("https://community.powerbi.com/t5/Desktop/How-to-expand-all-nested-tables-at-once-table-expandtablecolumn/m-p/129451#U129451")), Data0 = Source{0}[Data], ChildrenWithTable = Table.SelectRows(Data0, each [Children] is table), fnCombineAll = (TableSoFar as table, newChildren as table) as table => let Combined = Table.Buffer(Table.Combine(List.Union({{TableSoFar},newChildren[Children]}))), ChildrensChildrenWithTable = Table.AddColumn(newChildren, "ChildrensChildren", each Table.SelectRows([Children], each [Children] is table)), ChildrensChildrenCombined = Table.Combine(ChildrensChildrenWithTable[ChildrensChildren]), CombinedAll = if Table.RowCount(ChildrensChildrenCombined) = 0 then Combined else @fnCombineAll(Combined, ChildrensChildrenCombined) in CombinedAll, CombinedAll = if Table.RowCount(ChildrenWithTable) = 0 then Data0 else fnCombineAll(Data0, ChildrenWithTable), #"Added Index" = Table.AddIndexColumn(CombinedAll, "Index", 1, 1), #"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Kind", "Name", "Children", "Text"}) in #"Reordered Columns"
MarcelBeug
Community Champion
9 years agoThe code below expands all nested tables from this webpage (as an example) as requested, but I'm note sure if the result makes much sense.
It includes an embedded recursive function fnCombineAll.
Possibly some further refinement would be required, but at least we have a start.
let
Source = Web.Page(Web.Contents("https://community.powerbi.com/t5/Desktop/How-to-expand-all-nested-tables-at-once-table-expandtablecolumn/m-p/129451#U129451")),
Data0 = Source{0}[Data],
ChildrenWithTable = Table.SelectRows(Data0, each [Children] is table),
fnCombineAll = (TableSoFar as table, newChildren as table) as table =>
let
Combined = Table.Buffer(Table.Combine(List.Union({{TableSoFar},newChildren[Children]}))),
ChildrensChildrenWithTable = Table.AddColumn(newChildren, "ChildrensChildren", each Table.SelectRows([Children], each [Children] is table)),
ChildrensChildrenCombined = Table.Combine(ChildrensChildrenWithTable[ChildrensChildren]),
CombinedAll = if Table.RowCount(ChildrensChildrenCombined) = 0 then Combined else @fnCombineAll(Combined, ChildrensChildrenCombined)
in
CombinedAll,
CombinedAll = if Table.RowCount(ChildrenWithTable) = 0 then Data0 else fnCombineAll(Data0, ChildrenWithTable),
#"Added Index" = Table.AddIndexColumn(CombinedAll, "Index", 1, 1),
#"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Kind", "Name", "Children", "Text"})
in
#"Reordered Columns"
cpinho
Advocate I
9 years agoHi Marcel,
Thank you very much for you great assistance. Trying to put it working together. But sometimes is just a mess.