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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
OPS-MLTSD
Post Patron
Post Patron

How to calculate proportion in each subcategory of a larger category

Hello, I am trying to count the proportion of events in each category exactly like what this persion has done in this tutorial: https://bielite.com/blog/calculating-percent-of-subtotal/
 
Youtube link to the same tutorial: https://www.youtube.com/watch?v=AJxCCfFmLTQ
 
I followed their guideline and tried to create a measure for my visual, however, I am getting an error, I have posted my calculation at the bottom, if someone could please help me fix this error, that would be much appreciated. 
 
Event Proportion % =
VAR Groupall = VALUES(Group[Group])
VAR categorytype = VALUES('Events'[categorytype])
VAR categoryname = VALUES('Events'[categoryname])
VAR eventcount = DISTINCTCOUNT('Events'[EventID])
VAR eventnames =
SWITCH(
TRUE(),
ISINSCOPE('Events'[event name]),CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Group), Group[Group] IN Groupall, ALLSELECTED('Events'), 'Events'[categorytype] IN categorytype, 'Events'[categoryname] IN categoryname),
ISINSCOPE('Events'[categoryname]), CALCULATE(DISTINCTCOUNT('Events'[EventID),ALLSELECTED(Group), Group[Group] IN Groupall, ALLSELECTED('Events'), 'Events'[categorytype] IN categorytype),
ISINSCOPE('Events'[categorytype]), CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Group), Group[Group] IN Groupall),
ISINSCOPE(Group[Group]),CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Group))
)
RETURN
IF(
ISINSCOPE(Group[Group]),
DIVIDE(eventcount, eventitems),
1
)
1 ACCEPTED SOLUTION
OPS-MLTSD
Post Patron
Post Patron

I was able to figure out the solution its this:

 

Event Proportion % =
VAR Groupall = VALUES(Group[Group])
VAR categorytype = VALUES('Events'[categorytype])
VAR categoryname = VALUES('Events'[categoryname])
VAR eventcount = DISTINCTCOUNT('Events'[EventID])
VAR eventnames =
SWITCH(
TRUE(),
ISINSCOPE('Events'[event name]),CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Group), Group[Group] IN Groupall, ALLSELECTED('Events'), 'Events'[categorytype] IN categorytype, 'Events'[categoryname] IN categoryname),
ISINSCOPE('Events'[categoryname]), CALCULATE(DISTINCTCOUNT('Events'[EventID),ALLSELECTED(Group), Group[Group] IN Groupall, ALLSELECTED('Events'), 'Events'[categorytype] IN categorytype),
ISINSCOPE('Events'[categorytype]), CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Group), Group[Group] IN Groupall),
ISINSCOPE(Group[Group]),CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Events),ALLSELECTED(Group))
)
RETURN
IF(
ISINSCOPE(Group[Group]),
DIVIDE(eventcount, eventitems),
1
)
 
basically I needed to add the allselected filter for the events table as well

View solution in original post

2 REPLIES 2
OPS-MLTSD
Post Patron
Post Patron

I was able to figure out the solution its this:

 

Event Proportion % =
VAR Groupall = VALUES(Group[Group])
VAR categorytype = VALUES('Events'[categorytype])
VAR categoryname = VALUES('Events'[categoryname])
VAR eventcount = DISTINCTCOUNT('Events'[EventID])
VAR eventnames =
SWITCH(
TRUE(),
ISINSCOPE('Events'[event name]),CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Group), Group[Group] IN Groupall, ALLSELECTED('Events'), 'Events'[categorytype] IN categorytype, 'Events'[categoryname] IN categoryname),
ISINSCOPE('Events'[categoryname]), CALCULATE(DISTINCTCOUNT('Events'[EventID),ALLSELECTED(Group), Group[Group] IN Groupall, ALLSELECTED('Events'), 'Events'[categorytype] IN categorytype),
ISINSCOPE('Events'[categorytype]), CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Group), Group[Group] IN Groupall),
ISINSCOPE(Group[Group]),CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED(Events),ALLSELECTED(Group))
)
RETURN
IF(
ISINSCOPE(Group[Group]),
DIVIDE(eventcount, eventitems),
1
)
 
basically I needed to add the allselected filter for the events table as well
amitchandak
Super User
Super User

@OPS-MLTSD , What ever is in scope removefilter for that using all or allselected or removefilters

 

example

SWITCH(
TRUE(),
ISINSCOPE('Events'[event name]),CALCULATE(DISTINCTCOUNT('Events'[EventID]),ALLSELECTED('Events'[event name])) ,

// add for other

)

 

no need of in clause if they are already joined with table or part of the same table

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors