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,
Can anyone support with calculation of percentages while analyzing survey results with multi-choice questions, please?
Data table is structured like below, simplified example (I know this structure is not very good, but restructuring is problematic):
Indicator | Main_Breakdown | Breakdown_Type | Breakdown | Value |
Indicator1 | Main | Main |
| 10 |
Indicator1 | Breakdown | Sex | Female | 6 |
Indicator1 | Breakdown | Sex | Male | 4 |
Indicator1 | Breakdown | Fruit preferred | Apple | 3 |
Indicator1 | Breakdown | Fruit preferred | Pear | 7 |
Indicator1 | Breakdown | Fruit preferred | Banana | 4 |
Indicator1 | Breakdown | Fruit preferred | Peach | 8 |
Indicator2 | Main | Main |
| 15 |
As you see, some indicators are disaggregated, some of those disaggregations are multi-choice i.e. sum of categories (fruit preference in the example above) is higher than total (sum of fruit preference is 22 , while total is 10).
How do I write a measure to deal with calculation of percent for such categories?
So that I can have at the end:
Apple | 30% |
Banana | 40% |
Pear | 70% |
Peach | 80% |
Thanks!
Solved! Go to Solution.
The code was missing an ALL():
Measure =
VAR _breakdowns =
CALCULATETABLE (
VALUES ( 'Table'[Indicator] );
FILTER ( 'Table'; 'Table'[Main_Breakdown] = "Breakdown" )
)
RETURN
DIVIDE (
CALCULATE (
SUM ( 'Table'[Value] );
FILTER (
ALLEXCEPT ( 'Table'; 'Table'[Breakdown]; 'Table'[Indicator] );
'Table'[Breakdown_Type] = "Fruit preferred"
)
);
CALCULATE (
SUM ( 'Table'[Value] );
FILTER (
all('Table');
'Table'[Main_Breakdown] = "Main"
&& 'Table'[Indicator] IN _breakdowns
)
)
)
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 |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
87 | |
64 |