cancel
Showing results for
Did you mean:
Highlighted
Frequent Visitor

## Sum based on count of categories.

Hello,

I have a problem with sum by counting categories.

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.

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

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

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

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

## Re: Sum based on count of categories.

Hi,

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
2 REPLIES 2
Highlighted
Super User IV

## Re: Sum based on count of categories.

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

My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Super User IV

## Re: Sum based on count of categories.

Hi,

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com

Announcements

#### August 2020 Community Challenge: Can You Solve These?

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

#### Community Blog

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

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

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

Top Solution Authors
Top Kudoed Authors