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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Iterate over table rows to calculate group subtotals

This is a bit of an odd post, since I have a workable solution to my task. I just can't help feeling there's a simpler, more elegant way to accomplish the task.

I have a hierarchical table of activities, subactivities, and complexity levels. I need to add a column that computes the percentage weight for each activity sublevel. Here's the table:

ActivitySubactivityLevelWeight
ASA011 
ASA021 
ASA032 
ASA042 
ASA052 
ASA063 
ASA073 
ASA084 
BSA091 
BSA102 
BSA112 
BSA123 
BSA134 
BSA144 
CSA151 
CSA161 
CSA171 
CSA181 
CSA191 
CSA202 
CSA212 
CSA223 
CSA233 
CSA243 
CSA254 
CSA264 

 

In the weight column, I want to compute the percentage contribution of each Subactivity for each combination of Activity and Level. For example, there are two Subactivity values for Activty = A and Level = 1, so these would each have a Weight = 50%. 

 

Here's my current code for the Weight column:

 

Weight = 
VAR tmpTable =
SUMMARIZE(
	'Data',
	'Data'[Activity],
	'Data'[Level],
	"Pct", DIVIDE(1, COUNTROWS(DISTINCT('Data'[SubActivity])), BLANK())
)
VAR currentActivity = [Activity]
VAR currentLevel = [Level]
VAR filteredTable = FILTER(tmpTable, [Activity] = currentActivity && [Level] = currentLevel)
VAR result = SUMX(filteredTable, [Pct])
RETURN
result

 

 

This just feels kludgy. How can I simplify this?

Many thanks!

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hi @Anonymous ,

you can try this:

ERD_0-1690439787056.png

Weight = 1 / CALCULATE(DISTINCTCOUNT(Table_[Subactivity]), ALLEXCEPT(Table_,Table_[Activity], Table_[Level]))

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

2 REPLIES 2
ERD
Community Champion
Community Champion

Hi @Anonymous ,

you can try this:

ERD_0-1690439787056.png

Weight = 1 / CALCULATE(DISTINCTCOUNT(Table_[Subactivity]), ALLEXCEPT(Table_,Table_[Activity], Table_[Level]))

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

@ERD Thanks so much! This is just what I was looking for. I need to get more familiar/comfortable with the ALLEXCEPT function.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.