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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
PhoebeDang
Regular Visitor

Formula for calculate percentage which change with other filter

Hi, 

 

I am unable to find the exact solution for my problem. Appreciate anyone help on the formula!!

This is the formula i have to calculate gender % under different countries. 

DIVIDE(CALCULATE(COUNT('Monthly Metrics'[Gender]),'Monthly Metrics'[Gender]="Yes"),CALCULATE(COUNT('Monthly Metrics'[Gender]),ALLSELECTED('Monthly Metrics'[Gender])))
 
'Monthly Metrics'[Gender]="Yes" -> this is filtering for Yes or No answer. 
 
I have a slicer with Yes and No from the same column [Gender]. If i choose Yes, the result is 100% for all countries, if I choose No, the result gets more than 100% for some countries. 
 
How do i change the DAX so that when i choose No on slicer, it does not show any number, because Yes is already filtered out, it is not supposed to count Yes anymore. 
 
2 ACCEPTED SOLUTIONS
v-rongtiep-msft
Community Support
Community Support

Hi @PhoebeDang ,

I see that  @lbendlin asked you for a relevant sample.

Please refer to my steps.

Please try to modify the formula.

Gender Percentage = 
VAR SelectedGender = SELECTEDVALUE('Monthly Metrics'[Gender], "All")
RETURN
IF(
    SelectedGender = "No",
    BLANK(),
    DIVIDE(
        CALCULATE(COUNT('Monthly Metrics'[Gender]), 'Monthly Metrics'[Gender] = "Yes"),
        CALCULATE(COUNT('Monthly Metrics'[Gender]), ALLSELECTED('Monthly Metrics'))
    )
)

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

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

Thank you. Actually i figured out the DAX: 

DIVIDE(CALCULATE(COUNT('Monthly Metrics'[Gender]),FILTER('Monthly Metrics','Monthly Metrics'[Gender]="Yes")),CALCULATE(COUNT('Monthly Metrics'[Gender]))). it seems simpler than i thought. it just need to use FILTER formula.  
 
I tried your formula, it does anwer my question here -> (How do i change the DAX so that when i choose No on slicer, it does not show any number), but it altered the Yes % to even smaller result due to ALLSELECTED. 
 
(Sorry i couldn't upload a sample because it's abit hard for me to create a sample that can explain my problem statement clearly...my actual dataset was quite large)

View solution in original post

3 REPLIES 3
v-rongtiep-msft
Community Support
Community Support

Hi @PhoebeDang ,

I see that  @lbendlin asked you for a relevant sample.

Please refer to my steps.

Please try to modify the formula.

Gender Percentage = 
VAR SelectedGender = SELECTEDVALUE('Monthly Metrics'[Gender], "All")
RETURN
IF(
    SelectedGender = "No",
    BLANK(),
    DIVIDE(
        CALCULATE(COUNT('Monthly Metrics'[Gender]), 'Monthly Metrics'[Gender] = "Yes"),
        CALCULATE(COUNT('Monthly Metrics'[Gender]), ALLSELECTED('Monthly Metrics'))
    )
)

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

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.

 

 

 

 

Thank you. Actually i figured out the DAX: 

DIVIDE(CALCULATE(COUNT('Monthly Metrics'[Gender]),FILTER('Monthly Metrics','Monthly Metrics'[Gender]="Yes")),CALCULATE(COUNT('Monthly Metrics'[Gender]))). it seems simpler than i thought. it just need to use FILTER formula.  
 
I tried your formula, it does anwer my question here -> (How do i change the DAX so that when i choose No on slicer, it does not show any number), but it altered the Yes % to even smaller result due to ALLSELECTED. 
 
(Sorry i couldn't upload a sample because it's abit hard for me to create a sample that can explain my problem statement clearly...my actual dataset was quite large)
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.