使用 "AND" 和 "OR" 过滤器的 DAX 计算公式 (PowerBI)
DAX Calculate Formula with both "AND" and "OR" filters (PowerBI)
环境:PowerBI
当我只有一个过滤器时,我有一个 DAX 公式可以按预期工作:
# Bot Responses = CALCULATE([countUniqueActivityId], customEvents[EventName]="BotMessageSend" )
.
但是,我需要添加一个额外的过滤器,其中仅满足两个其他条件之一是不够的:
customEvents[cd_Text]<>""
或 customEvents[cd_Attach]<>""
将 'AND' 和 'OR' 条件放在一起的正确语法是什么?
我试过了:
CALCULATE([countUniqueActivityId], customEvents[EventName]="BotMessageSend", OR(customEvents[cd_Text]<>"", customEvents[cd_Attach]<>""))
但这会导致错误:
A single value for column 'EventName' in table 'customEvents' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
编辑:它不再显示错误消息,但也不return任何值
我建议阅读这篇文章以获取更多详细信息,但一种可能性如下:
CALCULATE (
[countUniqueActivityId],
customEvents[EventName] = "BotMessageSend",
FILTER (
ALL ( customEvents[cd_Text], customEvents[cd_Attach] ),
OR ( customEvents[cd_Text] <> "", customEvents[cd_Attach] <> "" )
)
)
如果您想添加到现有过滤器上下文而不是替换它,请考虑使用 KEEPFILTERS 版本。
CALCULATE (
[countUniqueActivityId],
KEEPFILTERS ( customEvents[EventName] = "BotMessageSend" ),
KEEPFILTERS (
FILTER (
ALL ( customEvents[cd_Text], customEvents[cd_Attach] ),
OR ( customEvents[cd_Text] <> "", customEvents[cd_Attach] <> "" )
)
)
)
环境:PowerBI
当我只有一个过滤器时,我有一个 DAX 公式可以按预期工作:
# Bot Responses = CALCULATE([countUniqueActivityId], customEvents[EventName]="BotMessageSend" )
.
但是,我需要添加一个额外的过滤器,其中仅满足两个其他条件之一是不够的:
customEvents[cd_Text]<>""
或 customEvents[cd_Attach]<>""
将 'AND' 和 'OR' 条件放在一起的正确语法是什么?
我试过了:
CALCULATE([countUniqueActivityId], customEvents[EventName]="BotMessageSend", OR(customEvents[cd_Text]<>"", customEvents[cd_Attach]<>""))
但这会导致错误:
A single value for column 'EventName' in table 'customEvents' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
编辑:它不再显示错误消息,但也不return任何值
我建议阅读这篇文章以获取更多详细信息,但一种可能性如下:
CALCULATE (
[countUniqueActivityId],
customEvents[EventName] = "BotMessageSend",
FILTER (
ALL ( customEvents[cd_Text], customEvents[cd_Attach] ),
OR ( customEvents[cd_Text] <> "", customEvents[cd_Attach] <> "" )
)
)
如果您想添加到现有过滤器上下文而不是替换它,请考虑使用 KEEPFILTERS 版本。
CALCULATE (
[countUniqueActivityId],
KEEPFILTERS ( customEvents[EventName] = "BotMessageSend" ),
KEEPFILTERS (
FILTER (
ALL ( customEvents[cd_Text], customEvents[cd_Attach] ),
OR ( customEvents[cd_Text] <> "", customEvents[cd_Attach] <> "" )
)
)
)