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
Katja262373
Helper I
Helper I

Calculation of percentage and a piechart diagram

 

Dear all, happy new 2024 year!!
I'm currently struggling with the last calculation for my statistics research..
I’ve got a dataset with the European survey results (58.347  respondents, each with a separate ID number = column IDno in the spreadsheet).


The respondents are aged 15 to 90; they've answered the questions about xenophobia (question codes impcntr, imsmetn and imdfetn = the columns names) and these people who have chosen 4 as an answer in these columns can be considered xenophobic.

My goal is to make a piechart or a diagram with many pillars (one pillar per age) to show the percentage of xenophobes per age (for instance there are 129 respondents aged 88 and 11 out of them are xenophobic, so that's 8,5%  percent.. and there are 184 respondents aged 15 and 6 out of them are xenophobic and that's 3,2 percent).

 

 

I've created a dimension table Age (2), where I've put all ages of the respondents one by one:

Age (2) tableAge (2) table

 

Then I've linked the code column to the code column of the main table ('age') one to many.

age relationship.jpg

 

Here are my measures..
All xenophobes =
CALCULATE(COUNTROWS('age_'), 'age_'[imsmetn]=4 && 'age_'[imdfetn]=4 && 'age_'[impcntr]=4)

Percentage of xenophobes in EU_ = divide([Xenophobes_], DISTINCTCOUNT('age_'[idno]))


But something doesn't add up... here's my piechart, where i see the percentage numbers 2 times by every "slice" of a pie!

why?.. i can't understand this.. can anyone help me to solve this riddle...?

thank you in advance for your advise/support !!!!!

why.jpg

 

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @Katja262373 ,

Please try to use the following measures.

Xenophobes by Age Group = CALCULATE(COUNTROWS('age_'), 'age_'[imsmetn]=4 && 'age_'[imdfetn]=4 && 'age_'[impcntr]=4, ALLEXCEPT('age_', 'age_'[Age]))
Total Respondents by Age Group = DISTINCTCOUNT('age_'[idno])
Percentage of Xenophobes by Age Group = DIVIDE([Xenophobes by Age Group], [Total Respondents by Age Group])

vrongtiepmsft_0-1704247633962.png

Why my measure returns the wrong total? How to fix that? (vahiddm.com)

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

View solution in original post

4 REPLIES 4
v-rongtiep-msft
Community Support
Community Support

Hi @Katja262373 ,

Please try to use the following measures.

Xenophobes by Age Group = CALCULATE(COUNTROWS('age_'), 'age_'[imsmetn]=4 && 'age_'[imdfetn]=4 && 'age_'[impcntr]=4, ALLEXCEPT('age_', 'age_'[Age]))
Total Respondents by Age Group = DISTINCTCOUNT('age_'[idno])
Percentage of Xenophobes by Age Group = DIVIDE([Xenophobes by Age Group], [Total Respondents by Age Group])

vrongtiepmsft_0-1704247633962.png

Why my measure returns the wrong total? How to fix that? (vahiddm.com)

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

 Dear Rongtie,

you are amazing! Thank you very much for your advice- it works now!

indeed, I overlooked the situation with filters and have filtered the AGE column as well, which has caused the erroneous calculation. Hereby my adjusted graph (I've chosen a pillar diagram instead of a pie chart). 
thank you for the link as well! !!

IMG_1101.jpeg

RainAndSnow
Regular Visitor

For visualizing something like, I'd suggest a horizontal bar chart instead of a pie so it's easier to view the anomalies across the ages. 

 

Depending on what you have selected under the "Data Labels", it looks like the percent inside the paranthesis is the percent of the total. I think you're wanting to select just "Data value" instead?

RainAndSnow_0-1704231266977.png

 

Hello Rainandsnow,

thank you very much for your advice! I've chosen the pillar diagram eventually. It looks good now! 

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.