cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Knez Frequent Visitor
Frequent Visitor

Percentage of grand total not calculated correctly

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:

 

total.png

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Percentage of grand total not calculated correctly

Hi @Knez ,

 

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 )

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

8 REPLIES 8
Community Support Team
Community Support Team

Re: Percentage of grand total not calculated correctly

Hi @Knez ,

 

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

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Knez Frequent Visitor
Frequent Visitor

Re: Percentage of grand total not calculated correctly

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:

 

with measure.png

 

Both the dataset and .pbix file are hosted here.

Community Support Team
Community Support Team

Re: Percentage of grand total not calculated correctly

Hi @Knez ,

 

Update the measure as below.

 

percentage = DIVIDE(DISTINCTCOUNT(Dummy_dataset[ID]), CALCULATE(DISTINCTCOUNT(Dummy_dataset[ID]), ALL(Dummy_dataset)))

23.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Knez Frequent Visitor
Frequent Visitor

Re: Percentage of grand total not calculated correctly

Hi @v-frfei-msft,

 

Thank you for the reply. Your solution works!

whole dataset.png

 

Howerver, when I apply any slicer, the values are wrong again:

 

sliced dataset.png

 

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!

Community Support Team
Community Support Team

Re: Percentage of grand total not calculated correctly

Hi @Knez ,

 

Please update the formula as below.

 

percentage = DIVIDE(DISTINCTCOUNT(Dummy_dataset[ID]), SUMX(ALLSELECTED(Dummy_dataset),CALCULATE(DISTINCTCOUNT(Dummy_dataset[ID]))))

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Knez Frequent Visitor
Frequent Visitor

Re: Percentage of grand total not calculated correctly

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.

Community Support Team
Community Support Team

Re: Percentage of grand total not calculated correctly

Hi @Knez ,

 

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 )

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

Knez Frequent Visitor
Frequent Visitor

Re: Percentage of grand total not calculated correctly

Hi @v-frfei-msft,

 

That solved it! Thank you!

Helpful resources

Announcements
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Kudoed Authors (Last 30 Days)
Users online (1,859)