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
ValeriaBreve
Post Patron
Post Patron

CountRows in a nested table

Hello,

I need to count the rows of each nested table (in a column "All") of a query.

I am trying to do so by adding a custom column into the nested tables and, for each cell, adding the total row count:

= Table.TransformColumns(
#"Previous Step",
{
{"All", each Table.AddColumn(_,"RowCount",each Table.RowCount(_))}}
)

But I am getting an error: Expression.Error: We cannot convert a value of type Record to type Table.

 

Can you please help me understand how to correct this?

Thanks!

Kind regards

Valeria

 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @ValeriaBreve, check this:

dufoq3_0-1710919864479.png

let
    Source = Table.FromList({#table(null, {{"a"}}), #table(null, {{"a"}, {"b"}})}, Splitter.SplitByNothing(), type table[All=table]),
    Ad_RowCountOuterColumn = Table.AddColumn(Source, "RowCount as Outer Column", each Table.RowCount([All]), Int64.Type),
    Ad_RowCountToAllTablesInner = Table.TransformColumns(Ad_RowCountOuterColumn, {{"All", each Table.AddColumn(_, "RowCount", (x)=> Table.RowCount(_), Int64.Type), type table}})
in
    Ad_RowCountToAllTablesInner

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

7 REPLIES 7
dufoq3
Super User
Super User

Hi @ValeriaBreve, check this:

dufoq3_0-1710919864479.png

let
    Source = Table.FromList({#table(null, {{"a"}}), #table(null, {{"a"}, {"b"}})}, Splitter.SplitByNothing(), type table[All=table]),
    Ad_RowCountOuterColumn = Table.AddColumn(Source, "RowCount as Outer Column", each Table.RowCount([All]), Int64.Type),
    Ad_RowCountToAllTablesInner = Table.TransformColumns(Ad_RowCountOuterColumn, {{"All", each Table.AddColumn(_, "RowCount", (x)=> Table.RowCount(_), Int64.Type), type table}})
in
    Ad_RowCountToAllTablesInner

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

@dufoq3 thank you! This works wonder. Can you please help me understand why - for the inner count -  using

"(x)=> "

works, whereas "each" does not? I am confused on this point.

Thanks again! 🙂  

Hi, you can substitute word each and its shortcut _ with any other character or string i.e.:

 

 

each _ = 0

 

is the same as

 

(myName)=> myName = 0

 

 

Try to google it or watch this video.

In this case you need to distinguish between

 

  • inner table (where I used (x)=>) and
  • outer table (where I used each _)

Maybe with this example you will understand better.

It filetrs rows where inner Column1 from table [Table1 to every row] equals outer Column1

 

dufoq3_0-1710924474966.png

 

let
    Table1 = #table(null, {{"a", 10}, {"b", 20}}),
    Table2 = #table(null, {{"a"}, {"b"}, {"c"}}),
    RepeatTable1ToTable2 = Table.AddColumn(Table2, "Table1 to every row", each Table1, type table),
    Ad_Table1Filtered = Table.AddColumn(RepeatTable1ToTable2, "Table1 filtered", 
       each Table.SelectRows([Table1 to every row], (x)=> x[Column1] = [Column1])
  , type table)
in
    Ad_Table1Filtered

 

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

@dufoq3 Thank you!

You're welcome Valeria.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

PhilipTreacy
Super User
Super User

Hi @ValeriaBreve 

 

Does your data look like this?

 

tabcol.png

 

If so, create another column and you can count the rows in a table with this

 

= Table.RowCount([Custom])

 

Do you need the row count entered into the table itself?

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Phil, yes that is how my query looks like! I need to enter the count in the table itself - as if there is more than 1 row in each nested table, I will need to perform other calculations - for each nested table.

That's what I was trying to do with the above formula - only I am not sure how to reference the nested tables in the countrows.... thanks!

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.