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

Percent By Group - Cluster Column - It Works Until a Filter is Applied

Hi All,

 

I have a clustered column chart that shows the percentages of "Status" within each "Group". Examples below with generic labels. 

 

DAX Code:

Status% = DIVIDE(
                        DISTINCTCOUNT('Table'[Item ID]),
                        CALCULATE(
                               DISTINCTCOUNT('Table'[Item ID]),
                               ALLEXCEPT('Table', 'Table'[Group])
                        )
                  ) + 0
 
This works perfectly, at first glance:
Configuration.jpg
Sample Table.jpg
 
However, when I use any of my slicers, the percentages are calculated incorrectly. It seems as though the denominator in the DAX formula is not being affected by the slicers. The numerator calculates properly with the slicers, but the denominator stays constant, giving me lower percentages that don't add to 100%.
 
Sample Table 2.jpg
 
Does anyone know of a way to alter my DAX formula so the slicers apply to the denominator? 
6 REPLIES 6
SteveCampbell
Memorable Member
Memorable Member

ALLEXCEPT removes all filters apart from GROUP, so this would make sense the filters do not affect it.

You can use a variable instead.Try:

Status% = 
VAR _group = SELECTEDVALUE ('Table'[Group]) 
RETURN
DIVIDE(
                        DISTINCTCOUNT('Table'[Item ID]),
                        CALCULATE(
                               DISTINCTCOUNT('Table'[Item ID]),
                                'Table'[Group]) = _group 
                        )
                  ) + 0

Love hearing about Power BI tips, jobs and news?
I love to share about these - connect with me!

Stay up to date on  linkedin-logo.png
Read my blogs on  powerbi.tips_.png



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



Hi Steve, thanks for replying!

 

I tried that DAX expression and received the following error:

 

"MdxScript(Model) (9, 5) Calculation error in measure 'Table'[Status%]: DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values."

Is 

SELECTEDVALUE ('Table'[Group]) 

and

 'Table'[Group]) = _group 

 from the same table? If not, check that they are the same data type



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



Yes sir.

Where do you get the error? Does the DAX in the measure underline any part



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



There is no red line. Below is the expression I entered with actual table/column names.

 

"Destination Contact Name" is a Text field

"Shipment EXTERNAL ID Type" is a Whole Number field

 

DAX Expression.jpg

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors