2

我有一个巨大的 excel 表,看起来像这样:

╔══════╦══════╦═════╗
║  A   ║  B   ║  C  ║
╠══════╬══════╬═════╣
║ Jack ║ 2001 ║ 1,5 ║
║ Jack ║ 2002 ║ 2,0 ║
║ Jack ║ 2003 ║ 1,0 ║
║ Jack ║ 3001 ║ 3,5 ║
║ Jack ║ 3002 ║ 4,0 ║
║ Jack ║ 3003 ║ 1,0 ║
║ Jill ║ 2001 ║ 3,0 ║
║ Jill ║ 2002 ║ 5,0 ║
║ Jill ║ 2003 ║ 2,0 ║
║ Jill ║ 3001 ║ 0,5 ║
║ Jill ║ 3002 ║ 6,0 ║
║ Jill ║ 3003 ║ 2,5 ║
╚══════╩══════╩═════╝

B 列包含许多不同的数字,但它们都以数字 2、3 或 8 开头。B 列中的数字始终为 4 位;我只对检查第一个数字感兴趣。

我需要将 C 列的值相加,其中 B 列中相应单元格的第一个数字是2*,3*8*。我需要的是创建一个执行此操作的公式(Ruby-esque 伪代码):

sum = 0
spreadsheet_rows.each do |row|
  if row.a == "Jack" and row.b == "2*" # Note the second wildcard condition.
    sum += row.c
  end
end

puts sum # Should print 4,5 in this example.

我正在尝试在 Excel 中使用以下公式来完成此操作:

=SUMIFS($C:$C; $A:$A; "Jack"; $B:$B; "=2*")

我知道 Excel 不支持数字的通配符条件,但是,我已将 B 列格式化为 Excel 中的“文本”类型,所以我认为它会被这样处理,但它似乎仍被视为 int。

是否有不同的方法=SUMIFS在 Excel 中为数字值应用通配符条件?也许有一种方法可以以某种方式将整数“转换”为公式中的字符串?我还没有找到办法(还)。

我正在使用 Excel for Mac 2011。

4

3 回答 3

3

I'd go for the less readable, but more powerful SUMPRODUCT:

=SUMPRODUCT(($A:$A="Jack") * (LEFT($B:$B;1)="2") * ($C:$C))

which will generate boolean arrays for each of the conditions (first and second brace part) which it will multiply with the third one (your numbers).

EDIT: As noted in comments, #VALUE errors can appear if any value in column C cannot be converted to a number. To avoid that, you could use the syntax suggested by barry houdini

=SUMPRODUCT(($A:$A="Jack") * (LEFT($B:$B;1)="2"); $C:$C)

and let SUMPRODUCT skip over non-numbers.

于 2014-09-01T09:13:08.060 回答
1

This works for me:

=SUM((A1:A12=F2)*(LEFT(B1:B12)=""&F3)*C1:C12)

entered as an array formula with CtrlShiftEnter

You ask how to cast numbers to strings; concatenating an empty string and a number ""&F3 is one way to do that.

enter image description here

于 2014-09-01T09:13:17.663 回答
0
{=SUM((A1:A12=F2)*(LEFT(B1:B12)=""&F3)*C1:C12)}

不需要如上所示的数组,只需键入以下公式即可得出与上述数组公式相同的结果

=SUMPRODUCT((A1:A12=F2)*(LEFT(B1:B12)=F3&"")*C1:C12)

记住差异[Arrays=""&F3] vs [SUMPRODUCT= F3&""] 我会带给你的那种我很高兴看到你的工作和你权威地提出问题的方式

  "I know that Excel does not support wildcard conditions for numbers, however, I have 
   formatted column B as type "Text" in Excel, so I thought it would be treated as 
   such, but it appears that it is still treated as an int."

仅当我们必须在 TEXT 中获得输出时,SUMPRODUCT 才起作用希望您对以上所有内容进行验证并在显眼处突出显示

于 2020-01-31T06:17:29.943 回答