Forum Discussion

dikssha's avatar
dikssha
Regular Visitor
5 months ago
Solved

Change in category selection changes selected subcategory in slicers

I have a table which has 2 columns: Category and Sub-category. Category are A, B, C and sub category are A1,A2, A3, B1, B2, C1,C2,C3,C4. I am using both column in the slicer. Both slicers have been s...
  • vojtechsima's avatar
    5 months ago

    Hey, dikssha ; you can pull this off with a hack, sort of.

     

    The thing with the non-disappearing previous selection is not fixable with default visuals; however, you can hack and adjust the behaviour.

     

    The solution can look like this:

    I have selected category B and subcategory B2. The table shows B2 correctly.

    Then I select Category C. Subcategory will render C values with the B2 still selected. The table, however, will show hte first value for C category, so C1.

     

    Lastly, I select new subcategory in C, so the B value will dissapear and Table will react to the subcategory selection.

     

    If you have enough values, technically the preselected value can kinda dissapear. I don't think there's currently better way to do it.

     

    The DAX that controls is set as Filter on visual level:

    Measure Filter = 
    
    var selectedCategory = SELECTEDVALUE(category[category])
    
    var selectedSubCategory = SELECTEDVALUE(subcategory[subcategory])
    
    var validSubCategories = 
    CALCULATETABLE(
        VALUES(subcategory[subcategory]),
        subcategory[category] = selectedCategory,
        REMOVEFILTERS(subcategory)
    )
    
    var isValidSelection = selectedSubCategory IN validSubCategories
    
    var alternativeSubCategory = MINX(validSubCategories, subcategory[subcategory])
    
    var targetSubCategory = IF(isValidSelection, selectedSubCategory, alternativeSubCategory)
    
    var finalResult = 
    CALCULATE(
        COUNTROWS('Table'),
        KEEPFILTERS(TREATAS({targetSubCategory}, 'Table'[subcategory])),
        REMOVEFILTERS(subcategory)
    )
    
    return finalResult

     

    The model looks like this:

     

    I deliberately don't have a subcategory connected, which is a big disadvantage; to you can try playing with it, whether you make it work with the physical connection. Alternatively, if this is functionality just for one visual, you can have a separate dimension just for this, and then keep the rest of the report standard with proper relationships.

     

    I am also attaching the report; you can try it yourself.

  • donbuser's avatar
    5 months ago

    This is a really common issue when you have dependent slicers but no enforced relationship in the selection behavior.

    From a technical side, Power BI doesn’t natively “reset” one slicer based on another selection — it will hold the last selected value, which is why you’re seeing blanks when the category changes.

    A couple of approaches you could consider:

    Using a hierarchy (Category → Subcategory) in a single slicer so the selections stay aligned
    Creating a measure to handle default logic and avoid blanks in visuals
    Or using synced slicers / bookmarks if you want more controlled behavior
    That said, this is also one of those cases where it helps to think about the user experience.

    If changing Category can invalidate Subcategory, it might be worth either:

    Clearing the subcategory selection automatically (instead of defaulting to one), or
    Guiding the user with a visual cue when the selection becomes incompatible
    I’ve run into similar situations where the bigger issue wasn’t the slicer behavior itself, but how easily a user could end up in a “no data” state without realizing why.

    Curious which direction you’re leaning — forcing a default selection, or making the interaction more transparent?