问题描述:

I have a sheet with basically a dictionary of key/value pairs. Keys are unique. In a second sheet I need to add one or more rows for every key in the dictionary with some data. In this very sheet I'd need to also report the proper value for each key.

To do so I have tried to combine the ARRAYFORMULA function with a number of other functions on the very first row of the second sheet to avoid (if possible) the need to copy the same formula on all rows of the value column.

So far, neither QUERY nor FILTER worked.

QUERY requires all data, there included the arguments to the WHERE predicate, to reside on a single sheet. In my case, the filtering key would be on the second sheet while the dictionary is on the first one. So this cannot be used at all.

FILTER seems to have a weird (to me) behavior when both used in conjunction with ARRAYFORMULA and without it.

You can have a look to my test Google Sheet

here or to snapshots here with ARRAYFORMULA (column B), without it (column C) and what I'd like to get (column D):

A little step further from pnuts' solution provides the "perfect" result without the "N/A" cells:

=ARRAYFORMULA(IF(A3:A="";"";VLOOKUP(A3:A;KEYS!A1:B;2;FALSE)))

Of course there is a major impact on the performances as the VLOOKUP is run once for every single line in in the second sheet (and this was also why I was trying to use FILTER).

Those performances are quite low even with the currently linked example sheet, which is really skinny.

网友答案:

In Row3 please try:

=ArrayFormula(vlookup(A3:A;KEYS!A$1:B$5;2;0))
网友答案:

Try:

=ARRAYFORMULA(IF(LEN(A3:A); VLOOKUP(A3:A;KEYS!A1:B;2;FALSE);))

That should get the keys, as far as values are entered in col A.

相关阅读:
Top