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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
porkaloca
New Member

How to show percentages on Stacked bars chart? Filters ignored in measure

Hi everyone,

New PBI user so probably I'm asking something very basic, but I don't understand where I'm wrong.

Any help is appreciated.

 

I need to display some values in a stacked bars chart as percentage of the total for the category (and not of the grand total).

below a screenshot:

Capture.PNG

 

The chart on top is my safe base, based on the count.

So, I created a new measure and used it as y-axis value:

 

 

PERCENTAGE = COUNTROWS(TBL_SURVEYS)/CALCULATE(COUNTROWS(TBL_SURVEYS),ALLEXCEPT(TBL_SURVEYS,TBL_SURVEYS[REGION]))

 

 

The chart seems to be right, but with the filter that  applied in the screen above I expect the percentage to be 100%..

That 20% of the first bar is correct on the total dataset, but not with the filters applied. Why the formula is ignoring the filters on the visual?

 

What am I missing?

 

Thanks!

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

It's ignoring the filters because you told it to with ALLEXCEPT. This function removes all filters except for the one(s) you specify to preserve (REGION in your case).

 

Without knowing what your data and filters look like, I don't know the best way to rewrite your measure but you might be able to fix it by adding in an ALLSELECTED to restore some of the filtering.

PERCENTAGE =
DIVIDE (
    COUNTROWS ( TBL_SURVEYS ),
    CALCULATE (
        COUNTROWS ( TBL_SURVEYS ),
        ALLSELECTED ( TBL_SURVEYS ),
        ALLEXCEPT ( TBL_SURVEYS, TBL_SURVEYS[REGION] )
    )
)

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

It's ignoring the filters because you told it to with ALLEXCEPT. This function removes all filters except for the one(s) you specify to preserve (REGION in your case).

 

Without knowing what your data and filters look like, I don't know the best way to rewrite your measure but you might be able to fix it by adding in an ALLSELECTED to restore some of the filtering.

PERCENTAGE =
DIVIDE (
    COUNTROWS ( TBL_SURVEYS ),
    CALCULATE (
        COUNTROWS ( TBL_SURVEYS ),
        ALLSELECTED ( TBL_SURVEYS ),
        ALLEXCEPT ( TBL_SURVEYS, TBL_SURVEYS[REGION] )
    )
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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