Power BI:将多个切片器关系更改为OR或AND [英] Power BI: Changing multiple slicer relationship to be OR not AND

查看:68
本文介绍了Power BI:将多个切片器关系更改为OR或AND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Power BI中,您可以根据数据中的不同条件使用多个切片器,例如一种形状,另一种颜色.这些切片器之间或其中的相互作用意味着,如果我选择圆形"和红色",则结果将仅是红色圆圈.它将过滤到同时满足两个切片器的那些条目.有没有一种方法可以设置Power BI切片器,以便如果我选择圆形"和红色",我将同时获得所有红色和所有圆形结果(例如,只需要满足一个切片器)?

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)?

在这里,我想返回1,4,5,6行.

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

任何帮助将不胜感激!

推荐答案

已编辑.正如亚历克西斯(Alexis)在评论中指出的那样,一开始我有这个错误.感谢您的轻柔轻推!

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

在没有数据模型的其他细节的情况下,我假设一个简单的维模型具有唯一颜色的"Colours"维和唯一形状的"Shapes"维,每个维都与事实建立了1:N关系名为"FactTable"的表.正如Alexis在评论中指出的那样,要驱动这种行为,我们需要构建断开连接的表来驱动切片器.

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.

第一个VAR根据互连的颜色上下文说明事实中是否有任何数据.第二个形状相同.如果其中一个为真,则返回TRUE.

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.

您可以在[EitherCondition] = 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.

关键部分是DAX中的过滤器上下文始终是逻辑AND情况.获取逻辑或"的唯一方法是评估多个表达式,并提出一种将它们组合在一起以适合您的情况的方法.

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.

这是模型图:

以及采取的措施:

这篇关于Power BI:将多个切片器关系更改为OR或AND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆