在两个表中使用OR条件进行计算 [英] CALCULATE with OR condition in two tables

查看:86
本文介绍了在两个表中使用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屋!

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