简体   繁体   English

在 Excel 2007 中,如何对命名范围中的多列进行 SUMIFS 索引?

[英]In Excel 2007, how can I SUMIFS indices of multiple columns from a named range?

I am analysing library statistics relating to loans made by particular user categories.我正在分析与特定用户类别的贷款相关的图书馆统计数据。 The loan data forms the named range LoansToApril2013.贷款数据形成命名范围 LoansToApril2013。 Excel 2007 is quite happy for me to use an index range as the sum range in a SUMIF: Excel 2007 很高兴我使用索引范围作为 SUMIF 中的总和范围:

=SUMIF(INDEX(LoansToApril2013,0,3),10,INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))

Here 10 indicates a specific user category, and this sums loans made to that group from three columns.这里的 10 表示一个特定的用户类别,它汇总了三列向该组发放的贷款。 By "index range" I'm referring to the通过“索引范围”,我指的是

INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6)  

sum_range value. sum_range 值。

However, if I switch to using a SUMIFS to add further criteria, Excel returns a #VALUE error if an index range is used.但是,如果我切换到使用 SUMIFS 来添加更多条件,如果使用索引范围,Excel 将返回 #VALUE 错误。 It will only accept a single index.它只接受一个索引。

=SUMIFS(INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL") 

works fine工作正常

=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")

returns #value, and I'm not sure why.返回#value,我不知道为什么。

Interestingly,有趣的是,

=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")

is also accepted and returns the same as the first one with a single index.也被接受并返回与第一个具有单个索引的相同。

I haven't been able to find any documentation or comments relating to this.我找不到任何与此相关的文档或评论。 Does anyone know if there is an alternative structure that would allow SUMIFS to conditionally sum index values from three columns?有谁知道是否有一种替代结构可以让 SUMIFS 有条件地对三列的索引值求和? I'd rather not use three separate formulae and add them together, though it's possible.我宁愿不使用三个单独的公式并将它们加在一起,尽管这是可能的。

The sumifs formula is modelled after an array formula and comparisons in the sumifs need to be the same size, the last one mimics a single column in the LoansToApril2013 array column 4:4 is column 4. sumifs公式是在数组公式之后建模的,并且sumifs比较需要具有相同的大小,最后一个模拟LoansToApril2013数组列4:4的单个列是第4:4列。

The second to bottom one is 3 columns wide and the comparison columns are 1 column wide causing the error.倒数第二个是 3 列宽,比较列是 1 列宽导致错误。

sumifs can't do that, but sumproduct can sumifs不能这样做,但sumproduct可以

Example:例子:

X  1  1  1
Y  2  2  2
Z  3  3  3

starting in A1从 A1 开始

the formula =SUMPRODUCT((A1:A3="X")*B1:D3) gives the answer 3 , and altering the value X in the formula to Y or Z changes the returned value to the appropriate sum of the lines.公式=SUMPRODUCT((A1:A3="X")*B1:D3)给出答案3 ,并将公式中的值X更改为YZ将返回值更改为适当的行的总和。
Note that this will not work if you have text in the area - it will return #VALUE!需要注意的是,如果你有在该地区的文本这行不通的-它会返回#VALUE!

If you can't avoid the text, then you need an array formula.如果您无法避免文本,那么您需要一个数组公式。 Using the same example, the formula would be =SUM(IF(A1:A3="X",B1:D3)) , and to enter it as an array formula, you need to use CTRL + SHIFT + ENTER to enter the formula - you should notice that excel puts { } around the formula.使用相同的示例,公式为=SUM(IF(A1:A3="X",B1:D3)) ,要将其作为数组公式输入,您需要使用CTRL + SHIFT + ENTER输入公式- 您应该注意到 excel 将{ }放在公式周围。 It treats any text as zero, so it will successfully add up the numbers it finds even if you have text in one of the boxes (eg change one of the 1 's in the example to be blah and the total will be 2 - the formula will add the two remaining 1 s in the line)它将任何文本视为零,因此即使您在其中一个框中有文本,它也会成功地将找到的数字相加(例如,将示例中的1之一更改为blah ,总数将为 2 -公式将在行中添加两个剩余的1 s)

The two answers above and a bit of searching allowed me to find a formula that worked.上面的两个答案和一些搜索让我找到了一个有效的公式。 I'll put it here for posterity, because questions with no final outcome are a pain for future readers.我会把它放在这里供后代使用,因为没有最终结果的问题对未来的读者来说是一种痛苦。

=SUMPRODUCT( (INDEX(LoansToApril2013,0,3)=C4) * (INDEX(LoansToApril2013,0,1)="PTFBL") * INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))

This totals up values in columns 4-6 of the LoansToApril2013 range, where the value in column 3 equals the value in C4 (aka "the cell to the left of this one with the formula") AND the value in column 1 is "PTFBL".这汇总了 LoansToApril2013 范围的第 4-6 列中的值,其中第 3 列中的值等于 C4 中的值(又名“带有公式的此单元格左侧的单元格”),第 1 列中的值为“PTFBL ”。

Despite appearances, it isn't multiplying anything by anything else.尽管出现,它并没有乘以任何其他东西。 I found an explanation on this page , but basically the asterisks are adding criteria to the function.我在这个页面上找到了一个解释,但基本上星号是为函数添加条件。 Note that criteria are enclosed in their own brackets, while the range isn't.请注意,标准括在自己的括号中,而范围则没有。

If you want to use names ranges you need to use INDIRECT for the Index commands.如果要使用名称范围,则需要对索引命令使用 INDIRECT。

I used that formula to check for conditions in two columns, and then SUM the results in a table which has 12 columns for the months (the column is chosen by a helper cell which is 1 to 12 [L4]).我使用该公式检查两列中的条件,然后将结果汇总到一个包含 12 列月份的表中(该列由 1 到 12 [L4] 的辅助单元格选择)。

So you can do if:所以你可以这样做:

Dept (1 column name range [C6]) = Sales [D6];部门(1列名称范围[C6])=销售[D6]; Region (1 column name range [C3]) = USA [D3];区域(1 列名称范围 [C3])= 美国 [D3]; SUM figures in the 12 column monthly named range table [E7] for that 1 single month [L4] for those people/products/line item那些人/产品/行项目的 12 列每月命名范围表 [E7] 中的 SUM 数字,用于该 1 个单月 [L4]

Just copy the formula across your report page which has columns 1-12 for the months and you get a monthly summary report with 2 conditions.只需在您的报告页面上复制公式,该页面的第 1-12 列代表月份,您将获得包含 2 个条件的月度总结报告。

=SUMPRODUCT( (INDEX(INDIRECT($C$6),0,1)=$D$6) * (INDEX(INDIRECT($C$3),0,1)=$D$3) * INDEX(INDIRECT($E7),0,L$4)) =SUMPRODUCT((INDEX(INDIRECT($C$6),0,1)=$D$6) * (INDEX(INDIRECT($C$3),0,1)=$D$3) * INDEX(INDIRECT($E7) ,0,L$4))

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

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