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
VictoriaTomaz
Frequent Visitor

Display Count in Pie Chart based on Condition

Hello, I have some sample data here:

IDClass
1A
1B
1C
2A
3A
3B
4A
4C

 

I'm trying to create a pie chart that displays a count of "Class" but I only want it to display the count where ID has both A & B present. So based on the data above, ID 1 and 3 would contribute to the count because they both have a Class which includes A and B. In the end I'm looking for my Pie Chart to look like this:

VictoriaTomaz_0-1707927809630.png

Looking for any assistance on how to write this measure properly. Thanks!

1 ACCEPTED SOLUTION
VictoriaTomaz
Frequent Visitor

In case anyone happens to stumble upon this post with the same question, this is the dax I ended up writing to help me figure out this issue:

 

Measure = 
VAR A = CALCULATETABLE(DISTINCT(Table[ID], Table[Class] = "A")
VAR B = CALCULATETABLE(DISTINCT(Table[ID], Table[Class] = "B")
VAR AB = INTERSECT(A, B)

RETURN
CALCULATE(

COUNTROWS(Table, Table[ID] IN AB)

 

And then in the visual tab of the pie chart, put this measure under "Values" and put the Class column from the table under "Legend".

View solution in original post

3 REPLIES 3
VictoriaTomaz
Frequent Visitor

In case anyone happens to stumble upon this post with the same question, this is the dax I ended up writing to help me figure out this issue:

 

Measure = 
VAR A = CALCULATETABLE(DISTINCT(Table[ID], Table[Class] = "A")
VAR B = CALCULATETABLE(DISTINCT(Table[ID], Table[Class] = "B")
VAR AB = INTERSECT(A, B)

RETURN
CALCULATE(

COUNTROWS(Table, Table[ID] IN AB)

 

And then in the visual tab of the pie chart, put this measure under "Values" and put the Class column from the table under "Legend".

Daniel29195
Super User
Super User

@VictoriaTomaz 

the requirement is confusing ( at least for me).

 

can you please explain the logic  ? like  in class A on the pie chart,  how do you get the 40% ? 

 

another question related, 

if id is in A and B , should i count it in A , and in B ? 
what about C class ? 

 

best regards

Sorry for the Confusion, Instead of doing percentages, I should of done it by counts instead kind of like this:

VictoriaTomaz_0-1707931335082.png

So A & B are 2 from ID's 1 and 3 adding to the count since they both have Class A and B in the table.

 

The reason C shows up is from ID 1, since it meets the reqirement of having both A & B, I also want it to count any other Classes in the chart outside of just A & B, hence why C shows up. 

 

I hope that makes sense!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.