cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: Sum based on count of categories.

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
Highlighted
Super User IV
Super User IV

Re: Sum based on count of categories.

@Han_Solo ,

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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Super User IV
Super User IV

Re: Sum based on count of categories.

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

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.

Top Solution Authors
Top Kudoed Authors