Forum Discussion

NMOORE's avatar
NMOORE
Helper II
1 year ago
Solved

Page Filter Conditional Multiple Category Selection

Hi,

 

In Power BI I have a table with a column with the following categories:

  • Within 25 Mile Radius
  • Within 40 Mile Radius
  • Outside 40 Mile Radius
  • No Postcode Available

 

How do I create a page filter with the following options & consequences:

  • Within 25 Mile Radius filters Within 25 Mile Radius
  • Within 40 Mile Radius filters Within 25 Mile Radius & Within 40 Mile Radius
  • Outside 40 Mile Radius filters Outside 40 Mile Radius
  • No Postcode Available filters No Postcode Available

 

So a normal filter except for the 2nd option in bold. I feel i need to create a reference table, connect in a data model then create a measure that affects the slicer.

 

Really appreciate any help.

  • Anonymous's avatar
    Anonymous
    1 year ago

    Thanks for Sergii24's concern about this issue.

     

    Hi, NMOORE 

    I am glad to help you.

     

    Yes, you can create a reference table, but you don't need to create a relationship between them.


    Since you did not give me some test data for testing, I assumed some test data myself:

     


    Then create a reference table:

     

    Reference Table = SELECTCOLUMNS(Table1,"Category",Table1[Category])

     


    Remember, do not create relationships between them:

     


    Then create a Measure:

     

    SelectedFilter = 
    VAR _selectedValue = SELECTEDVALUE('Reference Table'[Category])
    RETURN
    IF(
        NOT ISFILTERED('Reference Table'[Category]),
        1,
        SWITCH(
            TRUE(),
            _selectedValue = "Within 25 Mile Radius" && MAX(Table1[Category]) = "Within 25 Mile Radius", 1,
            _selectedValue = "Within 40 Mile Radius" && MAX(Table1[Category]) IN {"Within 25 Mile Radius", "Within 40 Mile Radius"}, 1,
            _selectedValue = "Outside 40 Mile Radius" && MAX(Table1[Category]) = "Outside 40 Mile Radius", 1,
            _selectedValue = "No Postcode Available" && MAX(Table1[Category]) = "No Postcode Available", 1,
            0
        )
    )
    

     


    Drag the Category field of the Reference Table to the Slicer:

     


    Then drag the Measure to the Filters panel and set it to 1:

     

    Result:

     

    I have attached the pbix file for this simple example below, I hope it helps.

     

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Fen Ling,
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Hi NMOORE, I don't think there is a simple way to acheive the desired result. You'd need to work with inactive relationships and calculate to pass a correct filter context for every calcualtion.

    Why don't use a simple multi-select option? 

    • NMOORE's avatar
      NMOORE
      Helper II

      Hi, thanks for replying. Unfortunately not. It's simply what the client wants and I agree, it needs to filter items inclusive of the radius. In regards to your initial comment, that's what I was thinking, happy to get things complicated regarding models, reltionships and DAX, usually find a solution but this one had me stumped!

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for Sergii24's concern about this issue.

     

    Hi, NMOORE 

    I am glad to help you.

     

    Yes, you can create a reference table, but you don't need to create a relationship between them.


    Since you did not give me some test data for testing, I assumed some test data myself:

     


    Then create a reference table:

     

    Reference Table = SELECTCOLUMNS(Table1,"Category",Table1[Category])

     


    Remember, do not create relationships between them:

     


    Then create a Measure:

     

    SelectedFilter = 
    VAR _selectedValue = SELECTEDVALUE('Reference Table'[Category])
    RETURN
    IF(
        NOT ISFILTERED('Reference Table'[Category]),
        1,
        SWITCH(
            TRUE(),
            _selectedValue = "Within 25 Mile Radius" && MAX(Table1[Category]) = "Within 25 Mile Radius", 1,
            _selectedValue = "Within 40 Mile Radius" && MAX(Table1[Category]) IN {"Within 25 Mile Radius", "Within 40 Mile Radius"}, 1,
            _selectedValue = "Outside 40 Mile Radius" && MAX(Table1[Category]) = "Outside 40 Mile Radius", 1,
            _selectedValue = "No Postcode Available" && MAX(Table1[Category]) = "No Postcode Available", 1,
            0
        )
    )
    

     


    Drag the Category field of the Reference Table to the Slicer:

     


    Then drag the Measure to the Filters panel and set it to 1:

     

    Result:

     

    I have attached the pbix file for this simple example below, I hope it helps.

     

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Fen Ling,
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • NMOORE's avatar
      NMOORE
      Helper II

      Hi,

       

      Appreciate the help on this one, I got it working. It was a bit trickier as I had to filter the whole page, and not just a table graphic, so I used this where I could then I had to do some new measures for cards and cumulative graph