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 August 31st. Request your voucher.

Reply
TFernandes_2022
Frequent Visitor

Count rows per group in power query

How can I do a count by group in the same table (Column = Count_Rows_by_Group)?

TFernandes_2022_0-1666838581673.png


I managed to do it by creating another table grouped by category, but I have several other tables to do this same process and that way the panel will be very heavy.

1 ACCEPTED SOLUTION
mussaenda
Super User
Super User

Hi @TFernandes_2022 

 

You just need to group your data by Categoria then count your rows.

You can paste this on a new blank query source to try.

 

mussaenda_0-1666846598919.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyMzIGko65iSn5RQqOSrE60UqWQAFzQ0N0YUOQQjMDDOWGZmBxEwxxc5C4BcgSLwVnqCBYrbk5ihjIJjNjCxQxsF2WxihiIBvMzQ0RYrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ordem = _t, Column1 = _t, Column2 = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Column2"}, {{"All", each _, type table [Ordem=nullable text, Column1=nullable text, Column2=nullable text]}, {"CountRowsbyGroup", each Table.RowCount(_), Int64.Type}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Ordem", "Column1"}, {"Ordem", "Column1"})
in
    #"Expanded All"

 

Hope this helps.

 

View solution in original post

1 REPLY 1
mussaenda
Super User
Super User

Hi @TFernandes_2022 

 

You just need to group your data by Categoria then count your rows.

You can paste this on a new blank query source to try.

 

mussaenda_0-1666846598919.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyMzIGko65iSn5RQqOSrE60UqWQAFzQ0N0YUOQQjMDDOWGZmBxEwxxc5C4BcgSLwVnqCBYrbk5ihjIJjNjCxQxsF2WxihiIBvMzQ0RYrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ordem = _t, Column1 = _t, Column2 = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Column2"}, {{"All", each _, type table [Ordem=nullable text, Column1=nullable text, Column2=nullable text]}, {"CountRowsbyGroup", each Table.RowCount(_), Int64.Type}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Ordem", "Column1"}, {"Ordem", "Column1"})
in
    #"Expanded All"

 

Hope this helps.

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors