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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Peter1975
Frequent Visitor

count how many tables exists in each column, and expand this column if there or 2 or more.

I want to count how many tables exists in each column. If there two or more than then i want to Expand this table.

In this example, column2 and column3 have to expand.

 

Who can help me with this? 

column1column2column3
abctabletable
deftablepqr
tablejkltable
ghimnostu

 

Greetz Peter

2 REPLIES 2
ImkeF
Community Champion
Community Champion

Hello @Peter1975 ,
you can try the following method:

let
    Source = #table({"Column1", "Column2"}, {{#table({}, {{}}), 1}}), 
    GetColumnNames = Table.FromList(Table.ColumnNames(Source)), 
    AddTableCount = Table.AddColumn(
        GetColumnNames, 
        "CountOfTableObjects", 
        each List.Count(List.Select(Table.Column(Source, [Column1]), (x) => Value.Is(x, Table.Type)))
    )
in
    AddTableCount

paste the code into the advanced editor and follow the steps.
It will return a table with one row for each column, giving the count of table objects.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thank you Imke for your answer.

Although this offers part of the solution, it does not quite give the solution to my problem.

 

I would like to degroup (expand) each column as soon as a column contains 2 or more tables.

I added some code, but i don't know how to fix the code in the loop-part.

Can you help me?

 

let
    Source = #table({"Column1", "Column2"}, {{#table({}, {{}}), 1}}), 
    GetColumnNames = Table.FromList(Table.ColumnNames(Source)), 
    NewColumnNames = List.Transform(GetColumNames,  each _ & "_"),
    AddTableCount = Table.AddColumn(
        GetColumnNames, 
        "CountOfTableObjects", 
        each List.Count(List.Select(Table.Column(Source, [Column1]), (x) => Value.Is(x, Table.Type)))
    )

  //here a loop for each column(if i have 10 columns for example)
  if [CountOfTableObjects]>1 
  then Table.ExpandTableColumn(Source, Column{1}, GetColumnNames, NewColumnNames)
  else
  next column
  //end of loop

in
TableCount

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors