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

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.

Reply
Anonymous
Not applicable

Calculation of percentages while analyzing survey results with multi-choice questions

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!

 

1 ACCEPTED 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
            )
        )
    )

View solution in original post

12 REPLIES 12

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.