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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.