【问题标题】:Sum if data exists in range and matches on another sheet如果数据存在于范围内并在另一张纸上匹配,则求和
【发布时间】:2019-07-18 12:00:24
【问题描述】:

我在 Google 表格中的数据是这样组织的:

表 1:

Label     Type
foo       B
bar       A
baz       _(empty cell)
qux       B

totalX    quantity
totalY    quantity

表 2:

Type    X      Y
A       2      5
B       1      3
C       3      4

我希望 Sheet1 中的“数量”对来自 Sheet2 的类型相关值求和。在此示例中,totalX 将是 4(1+2+1,或 Bx+Ax+Bx),totalY 将是 11(3+5+3,或 By+Ay+By) .

从概念上讲,totalX 中的公式可以查看 Sheet1 上“类型”列中的每个单元格,然后如果该单元格不为空白,它会在 Sheet2 上找到值并将其添加到总数中。在玩了SUMIF 和各种公式之后,我无法弄清楚如何最好地做到这一点。

【问题讨论】:

    标签: google-sheets sum google-sheets-formula array-formulas gs-vlookup


    【解决方案1】:

    通过http://igoogledrive.blogspot.com/2013/07/google-spreadsheet-advanced-vlookup-and.html

    要计算 totalX,如果 'Label' 和 'Type' 是各自工作表上的 A 列:

     =sum(iferror(arrayformula(if(B2:B="";"";iferror(if(match(B2:B;'Sheet2'!A2:A4;0);vlookup(B2:B;'Sheet2'!A1:C4;{2}*sign(row(B2:B));false)))))))
    

    并计算totalY

     =sum(iferror(arrayformula(if(B2:B="";"";iferror(if(match(B2:B;'Sheet2'!A2:A4;0);vlookup(B2:B;'Sheet2'!A1:C4;{3}*sign(row(B2:B));false)))))))
    

    使用ISERRORIFERROR 忽略空单元格和未找到的单元格。 VLOOKUP 获取实际值; {x}*sign 引用 Sheet2 中的相应列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多