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

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  



Anonymous
Not applicable

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  



Anonymous
Not applicable

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  



Anonymous
Not applicable

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