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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Sum based on count of categories.

Hello,

I have a problem with sum by counting categories. 
Capture1.PNG

I have a few categories and further in hierarchy places for those. There are categories with multiple places (like Canada) and there are categories with one place. I want to calculate total SUM of value1 for each category but when category has only 1 place, sum them up - then its sum based on the count of category.  

 

Capture2.PNG

 so where there is AFRICA, ASIA, AUSTRALIA, SOUTH AMERICA I want to have 65,79 (10,92 + 21,69 + 28,98 + 4,20)

I tried different measures:
(i know that with one below there is no IF condition)

 

AVG_Category = 
VAR _Category = MAX(data[Category])
RETURN 
CALCULATE(SUM(data[Value1]), 
    FILTER(ALL(data[Category], data[Place]), 
        CALCULATE(COUNT(data[Category]), 
            ALL(data[Category], data[Place]), 
                data[Category] = _Category) = 1 ))

 

or this one

 

AVG_Category1 = 
VAR _cat = MAX(data[Category])
VAR _one = CALCULATE(COUNT(data[Category]), ALL(data[Category], data[Place]), data[Category] = _cat)
RETURN
IF( _one = 1, 
    CALCULATE(SUM(data[Value1]), 
        FILTER(ALL(data[Category], data[Place]), 
            CALCULATE(COUNT(data[Category]), ALL(data[Category], data[Place]), data[Category] = _cat) = 1 )),
    CALCULATE(SUM(data[Value1]), ALL(data), data[Category] = _cat))

 

 but without big success 

 

Capture3.PNG

but instead of 884,92 it should be 65,79. 

 

Do you have any idea for solution? Where I make a mistake?

 

You can download file  here

note worth mentioning:

this is sample dataset, the main file has live connection dataset and a lot of date so I tried to come up anything without sumx, calculated columns, calculated tables because need it to be fast (unless in SSAS)

Also it would be used on the stacked bar chart so on axis would be only places without category drill through (tricky way with dynamic axis). 

 

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@Anonymous ,

Try like sumx(summarize(data,data[Category],"_max",max(data[Value1])),[_max])

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
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!

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.

Top Solution Authors