Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hey everyone,
I have a problem with Power BI not displaying values correctly when they are calculated as percentage of grand total.
The dataset I am working with is a survey, where 2300 people have responded on 10 question with "Yes"/"No", or, in some cases, didn't even have the question. There were 10 questions, so I unpivoted my table, with one column serving as key (where questions are stored), and the other serving as value (where answers are stored). There is also an ID column and 4 other columns that store "demographic-like" information and they are used as slicers.
My first chart shows absolute values of all the people that said "Yes" (this one works correctly) and it is calculated as "Count (Distinct)" IDs in the unpivoted table.
The other chart (the one below) should show the same thing, but in percentages. The chart is essentially the same as the first one, the only difference is that "Value" is displayed as "Percentage of grand total". The problematic behaviour is presented in the picture below:
As you can see on the first chart, out of 2300 people, around 600 (616 to be exact) have said "Yes" to wearing sneakers. However, in the second chart, the same percentage is calculated as 47.24% which is most certainly wrong (26.78% is the correct percentage).
From what I understand, there should be a measure that is used to calculate these percentages correctly?
How do I fix this?
Thanks.
P.S. If it is required, I can share both the dataset and .pbix file.
Solved! Go to Solution.
Hi @Anonymous ,
Sorry for my late reply. Please update the formula as below.
percentage = VAR a = CALCULATE ( DISTINCTCOUNT ( Dummy_dataset[id] ), ALLEXCEPT ( Dummy_dataset, Dummy_dataset[brand], Dummy_dataset[age_group], Dummy_dataset[country], Dummy_dataset[race] ) ) VAR b = DISTINCTCOUNT ( Dummy_dataset[id] ) RETURN DIVIDE ( b, a )
Hi @Anonymous ,
To create a measure as below to get the correct percentage of ID.
PERCENTAGE= DIVIDE(DISTINCTCOUNT(Dummy_dataset[ID]),CALCULATE(DISTINCTCOUNT(Dummy_dataset[ID]),ALLSELTED(Dummy_dataset))
Hi @v-frfei-msft,
Thank you for the reply.
I tried your solution, but I get the same numbers on my "percentage of grand total" chart:
Both the dataset and .pbix file are hosted here.
Hi @Anonymous ,
Update the measure as below.
percentage = DIVIDE(DISTINCTCOUNT(Dummy_dataset[ID]), CALCULATE(DISTINCTCOUNT(Dummy_dataset[ID]), ALL(Dummy_dataset)))
Hi @v-frfei-msft,
Thank you for the reply. Your solution works!
Howerver, when I apply any slicer, the values are wrong again:
78 people out of 291 that wear sneakers is not 3.39%.
Is there any way to modify the measure's formula, so it takes into account the values selected on the slicers?
Thanks!
Hi @Anonymous ,
Please update the formula as below.
percentage = DIVIDE(DISTINCTCOUNT(Dummy_dataset[ID]), SUMX(ALLSELECTED(Dummy_dataset),CALCULATE(DISTINCTCOUNT(Dummy_dataset[ID]))))
Hi @Anonymous ,
Sorry for my late reply. Please update the formula as below.
percentage = VAR a = CALCULATE ( DISTINCTCOUNT ( Dummy_dataset[id] ), ALLEXCEPT ( Dummy_dataset, Dummy_dataset[brand], Dummy_dataset[age_group], Dummy_dataset[country], Dummy_dataset[race] ) ) VAR b = DISTINCTCOUNT ( Dummy_dataset[id] ) RETURN DIVIDE ( b, a )
Hi @v-frfei-msft,
Thank you for the reply.
This new formula messed up the measure as a whole. Now it does not display the correct values even when the slicers are not applied.
I have updated the .pbix file on this link.
Thank you for your help.
User | Count |
---|---|
141 | |
113 | |
104 | |
78 | |
64 |
User | Count |
---|---|
136 | |
125 | |
107 | |
70 | |
61 |