Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
cpinho
Advocate I
Advocate I

How 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 Chris for PowerQuery, but i was unable to use it in Power BI.

 

Glad you can assist.

 

Best

Carlos

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

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"

 

Specializing in Power Query Formula Language (M)

View solution in original post

6 REPLIES 6
MarcelBeug
Community Champion
Community Champion

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"

 

Specializing in Power Query Formula Language (M)

I now see I should not have "gone" to the end of all steps but filled in the parameters for fnCombineAll, but... what parameters? What other tables have we besides the ones in this/provided url? I'm lost 😉 Can you explain a bit? (Is your code still relevant, so many years on??)

Dear Marcel, I've been trying to get your code to work but... I've changed the url and row (Source = Web.Page(Web.Contents("https://community.fabric.microsoft.com/t5/Desktop/How-to-expand-all-nested-tables-at-once-table-expa...")),
Data0 = Source{2}[Data],) but still... this code should expand all Children, right and check for children in children etc? What am I doing wrong?

Im new to Power BI and Im not sure how you would use the above code.

 

Do you have the steps on how to actually implement this?

 

Thanks

Hello,

 

@MarcelBeug

I need to do a similar thing as I also have rows with nested tables. Is there a way to do this via the UI?

 

Thank you

J

Hi Marcel,

 

Thank you very much for you great assistance. Trying to put it working together. But sometimes is just a mess.

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.