如何从 PowerBi 中的不同表格中添加数字?

How to add numbers from different tables in PowerBi?

我在尝试为 PowerBi 寻找求和函数时遇到问题。我有两个 table 人工和预算。我的劳动有以下几栏:

Section Amount invoice 1.a 1 1.b 1 1.c 1 1.a 2 1.d 0 2 1.q 2 1.c 3

我的预算 table 如下所示:

Section Budget-Amount 1.a 0 1.b 0 1.c 0 1.d 0 1.q . . .

我想要做的是在预算中添加另一列 table 命名预算剩余。这将做的是从人工中添加与当前行的部分相关的所有金额,然后从预算金额中减去该金额。

我查看了有关如何执行此操作的示例,但似乎只有使用相同 table 时的示例。但我也一直在阅读,计算功能比 sumif 更强大。

我试过如下使用计算函数: Remaining Budget = ('Budget'[Budget Amount])- CALCULATE(SUM('Labor'[Amount]),'Labor'[Section]='Budget Labor'[Section])

我得到的错误是 "The expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression."

很抱歉,如果这是一个愚蠢的问题,我似乎无法在网上找到正确的答案。

提前谢谢你。

错误很明显,但如果您还不知道它是什么意思,它就没用了。

CALCULATE args 2-N 可以采用简单的谓词,例如CALCULATE ( ..., 'Table'[Field] = <expression> )。这种类型的简单谓词只能引用一列。这是因为它们是在幕后重写的(更多关于此 ),并且重写不支持任意表达式。

您已尝试写入:'Labor'[Section] = 'Budget'[Section]。这是引用两列。

Remaining Budget =
VAR CurrentBudgetRowSection = 'Budget'[Section]
RETURN
  'Budget'[Budget Amount]
    - CALCULATE(
        SUM( 'Labor'[Amount] ),
        'Labor'[Section] = CurrentBudgetRowSection
      )

我们可以CALCULATE中的一个简单谓词中引用一个变量,所以我们首先在一个变量中捕获当前'Budget'行的部分然后引用在 CALCULATE 之后。