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
jerryr0125
New Member

Count of subcategories

Hi everyone  Using Power Query -

I am looking to do a count of subcategories by creating a new custom column.

Example:

 

Field-MainCategoryField-subcategory
A55
A33
B33
B

44

C77
D55
D44
D77



New

 

 

Field-MainCategoryField-subcategoryField-scount
A552
A332
B332
B

44

2

C771
D553
D443
D773

 

Basically - I am looking to create a new field Field-scount which is a count of occurances of the Field-MainCategory,

There are other important columns in the table so a group by will not do the trick.

 

Any ideas ? Thanks - Jerry

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

group by category, keep all rows as one column, count rows in 2nd and expand table column after. 

let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content], 
    group = Table.Group(Source, "Field-MainCategory", {{"all", each _}, {"Field-scount", Table.RowCount}}),
    expand = Table.ExpandTableColumn(group, "all", {"Field-subcategory"})
in
    expand

View solution in original post

1 REPLY 1
AlienSx
Super User
Super User

group by category, keep all rows as one column, count rows in 2nd and expand table column after. 

let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content], 
    group = Table.Group(Source, "Field-MainCategory", {{"all", each _}, {"Field-scount", Table.RowCount}}),
    expand = Table.ExpandTableColumn(group, "all", {"Field-subcategory"})
in
    expand

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.