Forum Discussion

bldorris's avatar
bldorris
New Member
8 years ago
Solved

Allow user to change condition between two slicers

I am new to Power BI, and am struggling to figure out how to allow a user to change the condition between two selection slicers.   My report is sourced from a single table that contains patients tr...
  • OwenAuger's avatar
    8 years ago

    Hi bldorris

     

    One way of acheiving this is (sample pbix here):

    1. Set up data model like this, with Sending/Receiving lookup tables connected to Transfers with inactive relationships, 

       

    2. Create a 'Slicer Option' table with values And/Or to choose the slicer behaviour.
    3. Create these measures. The Inclusion Flag looks at whether And/Or is selected. If And is selected, both Sending/Receiving filters are applied simultaneously and the # rows of Transfers returned. Otherwise, they are applied separately and the row counts summed.
      Slicer Behavior = 
      SELECTEDVALUE ( 'Slicer Option'[Slicer Option], "And" )
      
      Inclusion Flag = 
      SWITCH (
          [Slicer Behavior],
          "And", CALCULATE (
              COUNTROWS ( Transfers ),
              USERELATIONSHIP ( Transfers[Receiving], Receiving[Receiving] ),
              USERELATIONSHIP ( Transfers[Sending], Sending[Sending] )
          ),
          "Or", CALCULATE (
              COUNTROWS ( Transfers ),
              USERELATIONSHIP ( Transfers[Receiving], Receiving[Receiving] )
          )
          + CALCULATE (
              COUNTROWS ( Transfers ),
              USERELATIONSHIP ( Transfers[Sending], Sending[Sending] )
          )
      )
    4. For the visual you want to filter (e.g. a table showing rows of Transfers) add a visual level filter Inclusion Flag > 0 or Inclusion Flag is not blank.
    5. Add a slicer for 'Slicer Option'[Slicer Option] to choose between And/Or.

    Result looks like this:

     

     

    Regards,

    Owen