How to take only certain columns from a FILTER result?

Jonathan picture Jonathan · Nov 6, 2014 · Viewed 37.9k times · Source

I'm using FILTER to extract rows from a range, and want to take only certain columns. For example, I filter by D, but want only columns B,C in reverse order. I tried to use QUERY:

=QUERY(filter(B:D,D:D>=2), "select C,B") - Error: can't analyze query string for function QUERY parameter 2: NO_COLUMNC
=QUERY(filter(B:D,D:D>=2), "select *") - shows me all columns, so QUERY should work...

How do I QUERY the results of FILTER? Any other way to achieve this?

Answer

AdamL picture AdamL · Nov 7, 2014

When you are QUERYing a computed array, you need to use the Colx notation rather than column letters:

=QUERY(FILTER(B:D,D:D>=2),"select Col2, Col1")

which incidentally can be achieved by just using the QUERY:

=QUERY(B:D,"select C, B where D >= 2")

or just FILTER:

=FILTER({C:C,B:B},D:D>=2)