在Excel中的多行上使用SUMPRODUCT和OFFSET

时间:2016-10-12 08:01:20

标签: excel

我有一个关于在Excel中使用OFFSET的问题。 例如,我有一个表格,其值随年份而变化。 然后,我有一张表,其中一些值按年/月变化。

!!Click here for the tables!!

我想写一个公式,例如 = SUMPRODUCT((E2:E37)* OFFSET(A1,C2:C37,1),E2:E37) 但它返回#VALUE!

简而言之,我想在C2中使用一系列值:C37即{1,1,1,1,1,1,1,1,1,1,1,1,2,2,2 ,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3}获得阵列{0.03, 0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.05,0.05, 0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,},然后在SUMPRODUCT函数中使用该数组。

有人可以帮我解决#VALUE!问题

提前致谢!

1 个答案:

答案 0 :(得分:1)

显然(我不知道这一点)偏移是不寻常的,因为当与数组一起使用时,它可以返回一组范围对象作为第二个参数。如果将它传递给它们,大多数功能都无法处理。但如果你通过N功能,你会得到正确的答案。

=SUMPRODUCT((E2:E37)*N(OFFSET(A1,C2:C37,1)))

=SUMPRODUCT((E2:E37),N(OFFSET(A1,C2:C37,1)))

enter image description here

请注意,这些似乎提供了一个#Value数组!通过评估公式运行它们时出现错误,但这些错误在通过N函数后解决。

当然,以简单的方式执行此操作会更常见,并使用带有帮助列的Index或Vlookup。我在尝试使用单个数组公式而不使用Offset时首先想到的是: -

=SUM(E2:E37*MMULT(N(C2:C37=TRANSPOSE((ROW(A2:A4)-1))),B2:B4))

我认为Offset方式更容易,更有效。

但是在这种只有少数类别的特殊情况下你可以使用这个数组公式,这可能是最简单的方法: -

=SUM(CHOOSE(C2:C37+1,0,B2,B3,B4)*E2:E37)

以上公式仅适用于“键”的特殊情况。与查阅列中的行号相同。偏移方法可以很容易地适用于包含查找: -

=SUM((E2:E37)*N(OFFSET(A1,IFERROR(MATCH(C2:C37,A2:A4,0),0),1)))

See this reference