Power BI: Changing multiple slicer relationship to be OR not AND

匆匆过客 提交于 2021-01-29 07:48:44

问题


In Power BI you can have multiple slicers based on different criteria in the data, e.g. one on shape and one on colour. The interaction between or among these slicers means that if I were to select "circle" and "red" then the results would be about red circles only. It filters to those entries where BOTH slicers are met. Is there a way to set Power BI slicers so that if I selected "circle" and "red" I would get both all red and all circle results (e.g. only one slicer needs to be satisfied)?

Here I'd like to get rows 1,4,5,6 returned.

Any help would be hugely appreciated!


回答1:


Edited. As Alexis points out in the comments, I had this wrong at first. Thanks for the gentle nudge!

EitherCondition =
VAR MatchesColour =
    CALCULATE (
        COUNTROWS ( 'FactTable' ),
        KEEPFILTERS ( TREATAS ( VALUES ( 'ColoursDisconnected'[Colour] ), 'Colours'[Colour] ) )
) > 0
VAR MatchesShape =
    CALCULATE (
        COUNTROWS ( 'FactTable' ),
        KEEPFILTERS ( TREATAS ( VALUES ( 'ShapesDisconnected'[Shape] ), 'Shapes'[Shape] ) )
    ) > 0
RETURN
  MatchesColour || MatchesShape

With no other details of your data model, I'm assuming a simple dimensional model with a 'Colours' dimension of unique colours and a 'Shapes' dimension of unique shapes, each connected in a 1:N relationship with a fact table named 'FactTable'. As Alexis pointed out in comments, to drive this behavior, we need to build disconnected tables to drive the slicers.

Thus we have slicers populated from disconnected tables, and we have the table visual created with the related dimensions.

The first VAR says whether there is any data in the fact based on diconnected colour context. The second does the same for shape. If either is true, we return TRUE.

You can filter your visual on [EitherCondition]=True to remove the other values. Or you could build from here into a more complex measure.

The key part is that filter context in DAX is always a logical AND situation. The only way to get logical ORs is to evaluate multiple expressions and come up with a way to combine them that works in your situation.

Here's the model diagram:

And the measure in action:



来源:https://stackoverflow.com/questions/57815885/power-bi-changing-multiple-slicer-relationship-to-be-or-not-and

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!