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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Fusilier
Helper III
Helper III

Help with Measure

Help with measure
3 hours ago

Hi,

Probably best to illustrate what I am trying to achieve in PBI with the tables below in.

 

My data table consists of individual responses to a survey.

One of the questions is about safety in the neighbourhood and whether the respondent felt 'Fairly safe', 'Neither safe nor unsafe', 'Very safe' etc.

This table is a row count of the different responses by Age group: 

     
 Answer count:   
Age groupFairly safeNeither safe nor unsafeVery safeTotal Result
6523719769503
18-24514423
25-34717914164
35-4416910832309
45-5419114237370
55-6426214063465
Total Result9356802191834

 

 

 

I've then created a measure to calculate the percentage in each Age group who say they feel 'Fairly safe', Very safe etc:

 

% result    
Age groupFairly safeNeither safe nor unsafeVery safeTotal Result
6547.12%39.17%13.72%100.00%
18-2421.74%60.87%17.39%100.00%
25-3443.29%48.17%8.54%100.00%
35-4454.69%34.95%10.36%100.00%
45-5451.62%38.38%10.00%100.00%
55-6456.34%30.11%13.55%100.00%
Total Result50.98%37.08%11.94%100.00%

 

This is the measure:

Pct =
DIVIDE(
    [Count],
    CALCULATE(
        [Count],
        ALLSELECTED('All Responses (2)'[Answer count],'All Responses (2)'[answer])))
 
So, I'm half way there.
 What I am struggling with is a measure to calculate the difference between the % for each Age group and the total % to produce this result:
 
Difference to Total   
Age groupFairly safeNeither safe nor unsafeVery safe
65-3.86%2.09%1.78%
18-24-29.24%23.79%5.45%
25-34-7.69%11.09%-3.40%
35-443.71%-2.13%-1.59%
45-540.64%1.30%-1.94%
55-645.36%-6.97%1.61%
    
 
So for example
18-24, Fairly safe = 21.74%
Total, Fairly safe =  50.98%
Difference = -29.24%
 
I just can't get my head around how to write the measure. 
Pulling my hair out!
Can anybody help please?
Thanks in advance!
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Fusilier,

 

To start, I unpivoted the data in Power Query to look like this:

 

DataInsights_0-1722889418696.png

 

Measures:

 

Count = SUM ( 'All Responses (2)'[Answer Count] )
Pct = 
DIVIDE (
    [Count],
    CALCULATE ( [Count], ALLSELECTED ( 'All Responses (2)'[Category] ) )
)
Pct to Total Variance = 
VAR vPct = [Pct]
VAR vNumerator =
    CALCULATE (
        [Count],
        ALLSELECTED ( 'All Responses (2)' ),
        VALUES ( 'All Responses (2)'[Category] )
    )
VAR vDenominator =
    CALCULATE ( [Count], ALLSELECTED () )
VAR vCategoryTotal =
    DIVIDE ( vNumerator, vDenominator )
VAR vResult = vPct - vCategoryTotal
RETURN
    vResult

 

DataInsights_1-1722889525780.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@Fusilier,

 

To start, I unpivoted the data in Power Query to look like this:

 

DataInsights_0-1722889418696.png

 

Measures:

 

Count = SUM ( 'All Responses (2)'[Answer Count] )
Pct = 
DIVIDE (
    [Count],
    CALCULATE ( [Count], ALLSELECTED ( 'All Responses (2)'[Category] ) )
)
Pct to Total Variance = 
VAR vPct = [Pct]
VAR vNumerator =
    CALCULATE (
        [Count],
        ALLSELECTED ( 'All Responses (2)' ),
        VALUES ( 'All Responses (2)'[Category] )
    )
VAR vDenominator =
    CALCULATE ( [Count], ALLSELECTED () )
VAR vCategoryTotal =
    DIVIDE ( vNumerator, vDenominator )
VAR vResult = vPct - vCategoryTotal
RETURN
    vResult

 

DataInsights_1-1722889525780.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors