Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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?
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).
Solved! Go to Solution.
Hi,
You may download my PBI file from here.
Hope this helps.
Hi,
You may download my PBI file from here.
Hope this helps.
Try like sumx(summarize(data,data[Category],"_max",max(data[Value1])),[_max])
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
99 | |
80 | |
70 | |
60 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |