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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
claireberry
Frequent Visitor

Create a measure for a stacked column chart that suppress counts based on two conditions

Hi, I have a "population flag" table with a Category column with values of race(where Grouping = "race") and a Flag column with the values of either flag or blank. I have a "spinoff" table with race_c and count column( the count column has value of 1 for each row).  I want to create a measure where if race_c's matching counterpart in the Category column for a state( state code for "population flag" table, state for "spinoff" table), has a corresponding "flag" value, and if the count for the "spinoff" table for the state and race_c combination is less than 11, then return blank for the entire stacked column visual when state is in the x-axis, and this new measure in the y-axis, race_c as legend.

 

In other words, create a measure that looks at all races for the current state that are flagged (from the Population flag table, where Grouping = "race" and Flag = "Flag") and checks if any of those flagged races has a total count (from the Spinoff table) less than 11. If at least one flagged race meets that condition, the measure returns BLANK for every race in that state (thus hiding the entire state’s bar). Otherwise, it returns the current race’s count.

I have a prelimary code, however, this code created a measure that will suppress only the specific bar segment of the race that met the conditions, but I want the entire bar for that state to not show in a stacked column chart, if there is one race in a state that met the two conditions. 

Filtered_Race_Count =
VAR CurrentState = SELECTEDVALUE(Spinoff[state])
VAR _flagCheck =
    LOOKUPVALUE(
    'Population flag'[Flag],
    'Population flag'[State code], VALUE( SELECTEDVALUE(Spinoff[state]) ),
    'Population flag'[Category], SELECTEDVALUE(Spinoff[race_c])
)

VAR _spinoffCount =
    CALCULATE(
        SUM(Spinoff[count]),
        KEEPFILTERS(
            FILTER(
                Spinoff,
                Spinoff[state] = SELECTEDVALUE(Spinoff[state]) &&
                Spinoff[race_c]     = SELECTEDVALUE(Spinoff[race_c])
            )
        )
    )  
VAR CurrentRaceCount =
    CALCULATE(
        SUM(Spinoff[count]),
        Spinoff[state] = CurrentState,
        Spinoff[race_c] = SELECTEDVALUE(Spinoff[race_c])
    )RETURN
IF(
    // Hide this category if flagged and if total count ≤ 10
    _flagCheck = "Flag"
    && _spinoffCount <= 10,
    BLANK(),            // Return no value (hides the bar segment)
    _spinoffCount       // Otherwise, return the sum
)

 

population flags table:

StateCategoryGroupingPopulationState Codeflag
MontanaAmerican Indian or Alaska NativeRace7847330Flag
MontanaAsian or Pacific IslanderRace1322030Flag
MontanaBlack or African AmericanRace1118530Flag
South DakotaAmerican Indian or Alaska NativeRace8200746Flag
South DakotaAsian or Pacific IslanderRace1709946Flag
South DakotaBlack or African AmericanRace2643146Flag
UtahAmerican Indian or Alaska NativeRace5737849Flag
UtahBlack or African AmericanRace6370549Flag
MontanaWhite

Race 

89898830 
Utah White


Race

787999949 

 

 spinoff table

state namerace_cstatecount
MontanaAmerican Indian or Alaska Native301
UtahBlack or African American491
UtahBlack or African American491
UtahBlack or African American491
UtahAsian or Pacific Islander491
South DakotaWhite461
South DakotaWhite461
South DakotaWhite461
South DakotaWhite461
MontanaWhite301
MontanaWhite301
MontanaWhite301
MontanaWhite301
MontanaWhite301
MontanaWhite301
South DakotaWhite461
South DakotaWhite461
South DakotaWhite461
South DakotaWhite461
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
UtahWhite491
MontanaOther or multi-race301
UtahOther or multi-race491
UtahRace not stated491
UtahRace not stated491
UtahRace not stated491
UtahRace not stated491
UtahRace not stated491
UtahRace not stated491
UtahRace not stated491

At the end, I want it to look like this below, with no bar for Montana and Utah showing. ( don't worry about the number in the labels not match)

 

claireberry_0-1741899628763.png

1 REPLY 1
v-qiaqi-msftv
Community Support
Community Support

Hi @claireberry,

Could you please share a bit more about your scenario?

 

Please try to modify your DAX as:

Filtered_Race_Count =
VAR CurrentState = SELECTEDVALUE(Spinoff[state])
VAR FlaggedRaces =
    CALCULATETABLE(
        VALUES('Population flag'[Category]),
        'Population flag'[Grouping] = "race",
        'Population flag'[Flag] = "Flag",
        'Population flag'[State Code] = CurrentState
    )
VAR Check =
    COUNTROWS(
        FILTER(
            FlaggedRaces,
            VAR RaceCategory = 'Population flag'[Category]
            VAR RaceCount =
                CALCULATE(
                    SUM(Spinoff[count]),
                    ALL(Spinoff[race_c]),
                    Spinoff[state] = CurrentState,
                    Spinoff[race_c] = RaceCategory
                )
            RETURN RaceCount <= 10
        )
    ) > 0
RETURN
IF(Check, BLANK(), SUM(Spinoff[count]))

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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