问题
I was looking for the solution for this apparently easy problem, but failed so far. I have a table in Excel like this:
Column 1 Column 2
apples 1
apples 2
bananas 5
apples 3
bananas 4
What I need is a formula that returns an array of the values in column 2, based on the criteria on column 1. So if I choose "apples", my output array should be {1,2,3}. That output should be compatible for use inside of a standard SUM(SUMIFS()) formula.
Thanks in advance for any insight
Regards, André
Edit: The order of the elements in the output array is unimportant
回答1:
I assume you don't want something like this
=IF(A2:A6="apples",B2:B6,"")
For your example that will return your values along with "null strings" like this
{1;2;"";3;""}
You could use this version to return the values in ascending order
=SMALL(IF(A2:A6="apples",B2:B6),ROW(INDIRECT("1:"&COUNTIF(A2:A6,"apples"))))
That will give you
{1;2;3}
If you use that in another formula you'll need to "array enter" with CTRL+SHIFT+ENTER
来源:https://stackoverflow.com/questions/27827969/excel-formula-to-create-an-array-of-lookup-values-based-on-a-criteria