Forum Discussion

mjones24's avatar
mjones24
Frequent Visitor
8 years ago
Solved

Complex Filtering

Hi all,   I’ve been using Power BI for a while now, on and off. My customer has a requirement regarding complex, compound filters, which I’d like to understand if Power BI supports and how. I’ve de...
  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi mjones24,

     

    Default filter feature will use 'and logic to link all filters, so your customers goal is impossible to achieve through default filter.

    I'd like to write a measure to check conditions and return the result tag, then you can filter the result tag to filter the records who suitable the complex filter conditions.

     

    Sample:

    Filter Tag =
    VAR current_attr1 =
        LASTNONBLANK ( 'Table'[Attribute 1], 1 )
    VAR current_attr2 =
        LASTNONBLANK ( 'Table'[Attribute 2], 1 )
    VAR current_attr3 =
        LASTNONBLANK ( 'Table'[Attribute 3], 1 )
    VAR current_attr4 =
        LASTNONBLANK ( 'Table'[Attribute 4], 1 )
    VAR result =
        OR (
            AND ( current_attr1 IN { "a", "b" }, current_attr2 IN { "c", "d" } ),
            AND ( current_attr3 IN { "a", "b" }, current_attr4 IN { "c", "b" } )
        )
    RETURN
        IF ( result, 1, 0 )
    

     

     

    Notice:

    1. You can modify the AND,OR functions to change the link logic.

    2. If you want to add more conditions items, you can increase original items in variable list.(e.g.  current_attr1 IN { "a", "b" ,"c", "d"})

     

    Regards,

    Xiaoxin Sheng