在两个表中使用 OR 条件计算 [英] CALCULATE with OR condition in two tables
本文介绍了在两个表中使用 OR 条件计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了对蓝色产品或属于鞋类的产品的销售额求和,我使用以下 DAX 表达式:
In order to Sum the sales amount of blue products OR products that belong to category shoes, I'm using the following DAX expression:
CALCULATE(
SUM(Table[SalesAmount]),
FILTER(
Table,
Table[Color] = "Blue" ||
Table[Category] = "Shoes")
)
但是,这不适用于两个不同的表(颜色和类别),例如:
However, this doesn't work with two different tables (Colors and Categories), like:
CALCULATE(
SUM(Table[SalesAmount]),
FILTER(
Table,
Colors[Color] = "Blue" ||
Categories[Category] = "Shoes")
)
谁能帮忙?
谢谢!
推荐答案
在网上搜索导致我找到 这个论坛主题.借用 OwenAuger 的帖子,我提出以下公式:
Searching the web led me to this forum topic. Borrowing from OwenAuger's post, I propose the following formula:
CALCULATE(SUM(Table[SalesAmount]),
FILTER(SUMMARIZE(Table, Colors[Color], Categories[Category]),
Colors[Color] = "Blue" ||
Categories[Category] = "Shoes"))
我们通过使用 SUMMARIZE
创建一个包含我们需要的所有部分的单个表来绕过单个表的限制.
We get around the single table restriction by using SUMMARIZE
to create a single table that has all of the pieces we need.
这篇关于在两个表中使用 OR 条件计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文