Forum Discussion
bldorris
8 years agoNew Member
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...
- 8 years ago
Hi bldorris
One way of acheiving this is (sample pbix here):
- Set up data model like this, with Sending/Receiving lookup tables connected to Transfers with inactive relationships,
- Create a 'Slicer Option' table with values And/Or to choose the slicer behaviour.
- 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] ) ) ) - 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.
- Add a slicer for 'Slicer Option'[Slicer Option] to choose between And/Or.
Result looks like this:
Regards,
Owen
- Set up data model like this, with Sending/Receiving lookup tables connected to Transfers with inactive relationships,
OwenAuger
Super User
8 years agoHi bldorris
One way of acheiving this is (sample pbix here):
- Set up data model like this, with Sending/Receiving lookup tables connected to Transfers with inactive relationships,
- Create a 'Slicer Option' table with values And/Or to choose the slicer behaviour.
- 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] ) ) ) - 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.
- Add a slicer for 'Slicer Option'[Slicer Option] to choose between And/Or.
Result looks like this:
Regards,
Owen