Excel - Formula to create an array of lookup values based on a criteria

天涯浪子 提交于 2021-02-05 07:59:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!