Forum Discussion

Jaypearce's avatar
Jaypearce
Frequent Visitor
1 year ago
Solved

Power Bi Fomula - Exclude rows if other column is filtered

Hi all,   Hi all, I have am wondering if anyone can help me with this semi odd formula.   Basically I want to have a filter for when "cost center" is filtered for multiple items (e.g. "CC2" & ...
  • danextian's avatar
    1 year ago

    Hi Jaypearce 

    Create a disconnected table of cost centre and use a measure to visual filter your table.

    Cost Centre = 
    VALUES('Input Data'[Cost Center]) --Calc Table
    Exclude Filter = 
    VAR _count =
        COUNTROWS ( 'Cost Centre' )  // count how many cost centres are selected
    VAR _isfiltered =
        ISFILTERED ( 'Cost Centre'[Cost Center] )  // check if slicer is filtered at all
    VAR _result =
        SWITCH (
            TRUE (),
    
            // if only one selected or nothing selected, return full count (no exclusion)
            _count = 1 || NOT _isfiltered,
            COUNTROWS ( 'Input Data' ),
    
            // if multiple are selected, exclude them from the input data
            _isfiltered && _count > 1,
            COUNTROWS (
                EXCEPT (
                    VALUES ( 'Input Data'[Partner Cost Center] ),   // all partner cost centres
                    VALUES ( 'Cost Centre'[Cost Center] )           // exclude selected cost centres
                )
            )
        )
    RETURN
        _result
    

     

    Please see the attached pbix.