问题描述
我有一个表格,其中包含 5 个类别和单位,显示为 2 种类型,即实际和预算.
I have a table with 5 categories and units displayed into 2 types, Actual and budget.
我想过滤这个表.仅当在切片器中选择了 2 个或更多值时.像这样的东西.
I want to filter this table. Only when 2 or more values are selected in the slicer. Something like this.
我想添加一个度量,但不知道如何准确地使用 if 语句.
I though of adding a measure, but dont know how to work the if statement exactly.
Measure = IF(COUNTROWS(ALLSELECTED(Report[Shipment Group])) = 1, "Something which would not filter the units", SELECTEDVALUE(Report[Units], SUM(Report[Units])))
不确定这是否是正确的方法.想知道是否有任何其他方法是可能的.任何帮助都会有所帮助.提前谢谢你.
Not sure if this is correct approach.Would like to know if any other approach is possible. Any help would be helpful. Thank you in advance.
推荐答案
这是一个有点奇怪的要求,但我认为我有一些可行的方法.
This is a bit of an odd request, but I think I have something that works.
- 首先,您需要为切片器值创建一个单独的表(否则您无法控制自己想要的过滤方式).您可以点击新建表格按钮并将其定义如下:
Groups = VALUES(Report[Shipment Group])
将您的切片器设置为使用
Groups[Shipment Group]
而不是Report[Shipment Group]
.
如下定义您的新度量:
Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
SUM(Report[Units]),
SUMX(FILTER(Report,
Report[Shipment Group] IN VALUES(Groups[Shipment Group])),
Report[Units]))
或等价的
Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
SUM(Report[Units]),
CALCULATE(SUM(Report[Units]),
FILTER(Report,
Report[Shipment Group] IN VALUES(Groups[Shipment Group]))))
注意:仔细检查 Power BI 是否未在 Groups
和 Report
表之间自动创建关系.你不想这样.
Note: Double check that Power BI has not automatically created a relationship between the Groups
and Report
tables. You don't want that.
这篇关于PowerBI:切片器仅在选择超过1个值时才能过滤表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!