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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

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 )

 

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
v-frfei-msft
Community Support
Community Support

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

 

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

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.

Hi @Anonymous ,

 

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.
Anonymous
Not applicable

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!

Hi @Anonymous ,

 

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.

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 )

 

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

Hi @v-frfei-msft,

 

That solved it! Thank you!

Anonymous
Not applicable

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.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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