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
r-ramillien
Regular Visitor

Display how many companies have how many categories

Dear powerBI community,

 

I have a simple table like below:

___________________________________________________________

Company (string)    | Category (string)  | Other column 

___________________________________________________________

Co_A                       | Cat_1                     | A

Co_A                       | Cat_1                     | B

Co_A                       | Cat_2                     | C

Co_A                       | Cat_2                     | D

Co_B                       | Cat_2                     | E

Co_B                       | Cat_3                     | F

Co_B                       | Cat_3                     | G

Co_C                       | Cat_3                     | H

Co_C                       | Cat_2                     | I

Co_C                       | Cat_1                     | J

Co_D                       | Cat_1                     | K

 

I would like to display a cluster bar and a pie chart which shows how many companies have how many distinct categories.

For example

2 Companies have 2 Categories (because Co_A have Cat_1 and Cat_2 and Co_B have Cat_2 and Cat_3)

1 Company have 3 categories (because Co_D have Cat_1, Cat_2 and Cat_3)

 

I'm sure its pretty straightfoward for many of you, but I can't find a way to do it. I tried to create few custom measures, but I can't add them to the "legend" or "axis" of the chart 😞

 

Thank you for your help ! 🙂

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@r-ramillien One way, create an Axis table: 

Axis = GENERATESERIES(1,100,1)
 
The a measure: 
Measure =
VAR __AxisValue = MAX('Axis'[Value])
VAR __Table = SUMMARIZE('Table',[Company],"__Cat",COUNTROWS(DISTINCT('Table'[Category])))
RETURN
COUNTROWS(FILTER(__Table,[__Cat] = __AxisValue))
 
PBIX file is attached below sig.

@ 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...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@r-ramillien One way, create an Axis table: 

Axis = GENERATESERIES(1,100,1)
 
The a measure: 
Measure =
VAR __AxisValue = MAX('Axis'[Value])
VAR __Table = SUMMARIZE('Table',[Company],"__Cat",COUNTROWS(DISTINCT('Table'[Category])))
RETURN
COUNTROWS(FILTER(__Table,[__Cat] = __AxisValue))
 
PBIX file is attached below sig.

@ 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...

Hello,

 

Thank you, it work great !
I still have to understand how it works, but it works 🙂

 

Sorry, I cannot accept the answer right now, there is a problem with my account bound with the one of microsoft 365...

 

Best regards

amitchandak
Super User
Super User

@r-ramillien , to me it seems like

distinctcount(Table[Category]) with Company as legend in pie

Thank you for your response,

 

You're right about the distinct count, but my problem is more with the legend.

I need to have the number of companies with a specific number of categories, not the name of the company itself.

 

Best regards

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.