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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Grouping by number of subitem

I have a dataset made of products and categories. For example a category "Beverages" has 5 types of drinks, while "food" has 7. I can easily show
Food : 7
Beverages : 5

Now imagine that I have several hundreds of categories, and some of them has 5 products, some 6,some 8 etc.
I would like to group by number of products per category, so something like
Categories with 7 products : 19
Categoriea with 6 products : 16
Categories with 5 products : 21 etc
Is is possibile with a standard visual without DAX?
And if with DAX I'm not sure how to write this...
Thanks!
1 ACCEPTED SOLUTION
affan
Solution Sage
Solution Sage

Hi @Anonymous,

 

You can add a calculated column to the table as below

Category Count = VAR countr= COUNTROWS(FILTER(Table1,Table1[Category]=EARLIER(Table1[Category]))) 
Return "Categories with " & countr &  " products."

 

This will give you a count for the category against each row. Then you can use this column in  standard visuals like Matrix or Table.

 

CountCategories.png

 

I have generated a sample data with some retail categories and added products to each category. You can download the pbix from the link below and give it a try.

 

https://www.dropbox.com/s/tdi3elkayn3elrz/Category%20Count.pbix?dl=0

 

Please mark this post as an accepted solution if this helped you.

 

Regards,

Affan

 

View solution in original post

3 REPLIES 3
affan
Solution Sage
Solution Sage

Hi @Anonymous,

 

You can add a calculated column to the table as below

Category Count = VAR countr= COUNTROWS(FILTER(Table1,Table1[Category]=EARLIER(Table1[Category]))) 
Return "Categories with " & countr &  " products."

 

This will give you a count for the category against each row. Then you can use this column in  standard visuals like Matrix or Table.

 

CountCategories.png

 

I have generated a sample data with some retail categories and added products to each category. You can download the pbix from the link below and give it a try.

 

https://www.dropbox.com/s/tdi3elkayn3elrz/Category%20Count.pbix?dl=0

 

Please mark this post as an accepted solution if this helped you.

 

Regards,

Affan

 

Anonymous
Not applicable

Hi Affan

 

that is very helpful. The numbers I get are very weird but it's a very complicated model. So I got the logic behind it, now studying the EARLIER function.

thanks

Greg_Deckler
Super User
Super User

Can't think of a way with DAX. I think that the most straight-forward way with DAX would be to create a table like:

 

Table =
VAR __table = SUMMARIZE('Table',[Category],"__count",COUNT([Some Column]))
RETURN DISTINCT(__table[__count])

Something like that, didn't try it specifically. Then use this table column as your axis. I don't know, there's an issue somewhere in there I'm sure, will have to think about it.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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