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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors