Using XLOOKUP to return multiple (variable) rows



We have a spreadsheet which records many data on separate tabs. The workbook is typically used for a year, so there are a few thousand rows overall. We extract some of these data onto a daily printout of salient information. The current formula finds the date specified in the list of data from a different tab, and returns as many entries as there are for that date. I find the current formula (based on old Excel) difficult to troubleshoot and correct when there is an error. I can easily create an XLOOKUP formula to pick up the data from the first row we need, but I'm struggling to see how to get the other rows to display.

Tab name of the other tab is "CIP". On the Daily Report tab, the date of the report required is in cell N2.

Old formula:


New XLOOKUP formula which collects the relevant info - only for the first row! - and spills the other columns:

From reading help files, it seems I can use an array formula to look up an nth value, but each day there will be a different number of entries (rows). If there are none, the ISERROR returns a result of "", and I'd like to update this to IFERROR at the same time.

Unfortunately I'm not very good at structuring complex formulas and I end up getting tangled. Can anyone give me a formula for this?


First screenshot is the daily report showing the CIP information captured on the report using the old formula. 


Second screenshot shows the data from CIP tab with 10 entries on 1st Dec; 12 entries for 2nd Dec; 0 entries for 3rd Dec...


Can anyone assist with this?




4 Replies


Try the FILTER function.

First,, clear the output range - the FILTER formula will automatically spill to as many rows as needed.

Then select the top left cell of the output, and enter the formula


=FILTER(CIP!C6:N63847, CIP!M6:M63847=N2, "")

Hah! Genius, works like a dream, as simple and easy as I thought we should be able to do

For another part of the same report, I only want to report 2 columns, then miss one, then do the rest,.. So I simply adjust the array range to match the columns I want.

Thanks, GraemeNZ

best response confirmed by GraemeNZ (Contributor)


If you want to return non-adjacent columns, you can use another FILTER, or INDEX combined with SEQUENCE.


For example

=FILTER(FILTER(CIP!C6:N63847, CIP!M6:M63847=N2, ""), {1,1,0,1,1,1,1,1,1,1,1,1})

The 0 in 3rd place in {1,1,0,1,1,1,1,1,1,1,1,1} skips the 3rd column in C:N.



=FILTER(INDEX(CIP!C6:N63847, SEQUENCE(ROWS(CIP!C6:N63847)), {1,2,4,5,6,7,8,9,10,11,12}), CIP!M6:M63847=N2, "")

Here, {1,2,4,5,6,7,8,9,10,11,12} specifies the column numbers within C:N that you want to include.

You can also use this method to change the order in which the columns are returned - simply change the array {1,2,4,5,6,7,8,9,10,11,12}.

@Hans Vogelaar, this Filter - Index - Sequence with the column number array is perfect for my needs. I've changed the best response to here.

Thanks again