简体   繁体   English

Excel总和基于对另一个表中的代码和值的查找

[英]Excel sum based on lookup of code and values in another table

Given 2 named tables in Excel 2013 (or higher): 在Excel 2013(或更高版本)中给定2个命名表:

tblInvoice tbl发票

ID    InvRef    Total
1     I/123        45
2     I/234         8

tblDeliveries tbl交货

ID    InvRef    Amt
1     I/123      10
2     I/123      15
3     I/123      20
4     I/234       5
5     I/234       3

How can we get the tblInvoice[Total] to compute automatically using an Excel formula? 我们如何获得tblInvoice[Total]以使用Excel公式自动计算? ie in pseudocode: 即在伪代码中:

 tblDeliveries[Total] = SUM(tblDeliveries[Amt] WHERE MATCH InvRef)

I have tried this Excel formula in tblInvoice[InvTotal] but it is returning an incorrect value: 我已经在tblInvoice[InvTotal]尝试了这个Excel公式,但是返回的值不正确:

=SUMPRODUCT(SUMIF(tblDeliveries[InvRef],[InvRef],tblDeliveries[Amt]))

Also tried swapping the first and second parameters. 还尝试交换第一个和第二个参数。 Produces a different amount, but still incorrect: 产生不同的数量,但仍然不正确:

=SUMPRODUCT(SUMIF([InvRef],tblDeliveries[InvRef],tblDeliveries[Amt]))

If relevant, it is assumed that there is a 1:N relationship from tblInvoice[InvRef] : tblDeliveries[InvRef] and that tblInvoice[InvRef] is UNIQUE. 如果相关,假定有一个1:从N的关系tblInvoice[InvRef] tblDeliveries[InvRef]tblInvoice[InvRef]是独一无二的。

The syntax is incorrect for what you require. 语法不符合您的要求。

=SUMPRODUCT(SUMIF(tblDeliveries[InvRef],[@InvRef],tblDeliveries[Amt]))

The @ is the crucial difference. @是关键区别。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM