Professional Documents
Culture Documents
FILTER Formula To Return Non-Adjacent Columns in Any Order - Excel Campus
FILTER Formula To Return Non-Adjacent Columns in Any Order - Excel Campus
FILTER Formula To Return Non-Adjacent Columns in Any Order - Excel Campus
Formulas
Bottom Line: Learn how to return a limited number of columns that are not in the
original order with the FILTER function in Excel. Also discover how to make the
formula dynamic to prevent errors when inserting and deleting columns.
FILTER-Non-Adjacent-Columns-Any-Order.xlsx Download
https://www.excelcampus.com/functions/filter-non-adjacent-columns 1/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
https://www.excelcampus.com/functions/filter-non-adjacent-columns 2/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
Your email is safe with us & you are free to unsubscribe at any time
Click to enlarge
This was a great question from Melanie, a member of our Elevate Excel Training
Program. She found a solution that allowed her to return individual columns, but
they had to be in the same order as the source range.
https://www.excelcampus.com/functions/filter-non-adjacent-columns 3/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
One easy solution is to move the columns in the source range/table so that they are
adjacent to each other. However, that is not always ideal or possible if you have
multiple FILTER formulas for the same source range.
The good news is that we can use the INDEX function to create an array of non-
contiguous or non-adjacent columns in an order that is different from the
source data, which I explain in this post & video.
I also explain a technique for using a drop-down lists for the headers of the spill
range so that you or your users can quickly change the columns that are
returned.
=FILTER(INDEX(tblData,SEQUENCE(ROWS(tblData)),
{4,3,5}),tblData[Customer Name]=I3)
https://www.excelcampus.com/functions/filter-non-adjacent-columns 4/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
This can easily look complex or overwhelming when you first see it. However, we
are just using an INDEX formula for the array argument of FILTER to create an
array of non-adjacent columns. So let's look at that first.
=INDEX(array,row_num,col_num)
Typically when you use INDEX you only specify one row number and one column
number. However, we can also specify a list of numbers to return multiple rows and
columns in a spill range.
There are two ways we can specify the list of row and column numbers in the
INDEX arguments.
For the row_num argument of INDEX we need a list of all of the rows in the source
range or table.
The SEQUENCE function will create this list for us. We only need to specify the
rows argument in SEQUENCE and it will create a list from 1 to the number of rows
specified.
https://www.excelcampus.com/functions/filter-non-adjacent-columns 5/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
We can use the ROWS function to return the count of the number of rows in the
source range or table.
=SEQUENCE(ROWS(tblData))
There are currently 80 rows in the tblData table, but this formula will automatically
update as rows are added or deleted from the table.
For the col_num argument of INDEX we can specify the column numbers we want
to return. For this array we can use the list of column numbers in curly brackets. We
can also specify the order of the columns to return.
The following array will return columns 4, 3, and 5 from the table in that order.
{4,3,5}
https://www.excelcampus.com/functions/filter-non-adjacent-columns 6/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
So, the following formula will create an array of all the rows and only three
columns from the tblData table.
The include argument is used to specify the filter criteria, or rows to return from
the array.
The great part about FILTER is that the column(s) you specify in the include
argument do NOT need to be in the array. In the following example, the include
https://www.excelcampus.com/functions/filter-non-adjacent-columns 7/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
argument is filtering the rows for a specific Customer Name. However, the
Customer Name column is not included in the array that is returned by INDEX.
=FILTER(INDEX(tblData,SEQUENCE(ROWS(tblData)),
{4,3,5}),tblData[Customer Name]=I3)
You can still use all the same techniques for specifying multiple criteria in the
include argument. There are no limitations there. We do have dedicated training
section on the FILTER function, including multiple criteria, in our Elevate Excel
Training Program.
To avoid this issue, we can replace the hardcoded list with an XMATCH
formula.
https://www.excelcampus.com/functions/filter-non-adjacent-columns 8/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
The XMATCH function will do a lookup for the column headers that we specify
above the spill range of FILTER, and return the column numbers of each column
in an array (list). XMATCH returns a list because we are specifying a range of
multiple cells in its lookup_value argument.
Click to enlarge
XMATCH(H5:J5,tblData[#Headers])
https://www.excelcampus.com/functions/filter-non-adjacent-columns 9/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
Now when you add or delete columns from the table, XMATCH will automatically
update to return the new column numbers based on the lookups that it performs.
A side benefit of this technique is that it also makes it easy to add columns to the
results of the FITLER formula. You can just add a new column header in a blank
cell to the right of the headers, then adjust the XMATCH formula to include that
cell in the lookup_value range.
https://www.excelcampus.com/functions/filter-non-adjacent-columns 10/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
The spill range for FILTER will extend to the right with that one simple change.
This means that you or the users of your file can quickly change the columns that
are displayed in the resulting spill range of FITLER. There is essentially no
maintenance or refresh required to make those changes. In other words,
our arrays are very dynamic. 😉
Here's a tutorial on how to create those drop-down lists with the UNIQUE
function: How to Create a Dynamic Drop-down List that Automatically Expands.
Conclusion
So that's how you change the column order of your return array. I admit that
this solution is a bit complex. It may take some time to really study and understand
each component, but it sure makes for a fantastic interactive end-result.
This is also a great example of how powerful and useful the new Dynamic Array
Formulas truly are.
https://www.excelcampus.com/functions/filter-non-adjacent-columns 11/12
12/16/22, 8:19 PM FILTER Formula to Return Non-Adjacent Columns in Any Order - Excel Campus
https://www.excelcampus.com/functions/filter-non-adjacent-columns 12/12