Leila Gharani presenting FILTER and UNIQUE formulas for non-adjacent Excel columns

Get the FILTER Practice Workbook

Follow the employee salary example and practice returning non-adjacent columns with FILTER, SORT and UNIQUE.

Filter Employee Names and Positions by Salary

Our first objective is to generate a list of Employee Names and Positions for any employee whose salary is greater than an amount defined in cell J2.

Employee salary data showing Name and Position separated by two date columns

We want to build these results in a dynamic way.  If the salary threshold in cell J2 changes, we want our list to automatically update.

NOTE: For demonstration purposes, we’ve located the data and the lookup results next to one another on the same sheet.  This makes for easier testing.  There is no requirement for this arrangement. 

You can place the data and results on different worksheets or in separate workbooks. For dynamic array formulas linked between workbooks, both workbooks must be open.

Turn the Employee Data into an Excel Table

We want to ensure that newly added records to the table are seen by the lookup function, so we will turn the list of information into a proper Excel Table.  This will also make for easier to read formulas.

  1. Click somewhere in the range of data and press CTRL-T.
  2. In the Create Table dialog box, ensure the selected data range is correct (in this case, =$A$2:$F$68) and the “My table has headers” option is selected, then click OK.
  3. Consider removing the applied colors by setting the table style to None (upper-left color option).
  4. With a cell in the table selected, go to Table Design and enter TSal in the Table Name box.
Excel Table Design tab with the employee data table named TSal

Filter Rows by Salary with FILTER

We’ll use Excel’s FILTER function to return the rows we need, then a second FILTER to select the columns. FILTER is available in Microsoft 365, Excel 2021, Excel 2024, and Excel for the web.

If you’re not familiar with the FILTER function, click the link below for a great post and video on its use.

Excel’s New Dynamic Array FILTER Function

We’ll build this solution in stages, so we don’t have to think about too much at any single moment.

For the array argument, we need the columns from Name (B) through Position (E). This also brings in Start Date and Birth Date, which we’ll remove in the next step.

Begin by creating the beginning of the FILTER function in cell I5.

=FILTER(TSal[[Name]:[Position]],

For our Include argument, we want to discover any row with a salary greater than what is defined in cell J2 (100,000).

=FILTER(TSal[[Name]:[Position]], Tsal[Salary] > J2,

We could add a third optional argument that displays a message if no records are discovered.

=FILTER(TSal[[Name]:[Position]], Tsal[Salary] > J2, "No Records Found")

If no salaries meet the threshold, FILTER returns a #CALC! error unless you handle the empty result. When using nested FILTER formulas, you can wrap the complete formula in IFERROR to display a message instead.

For example:


=IFERROR(FILTER(FILTER(TSal[[Name]:[Position]],TSal[Salary]>J2),{1,0,0,1}),"No matching employees")

But we are confident we will always have at least one record returned, so we will leave that argument out of our formula for simplicity’s sake.

=FILTER(TSal[[Name]:[Position]], Tsal[Salary] > J2)

The formula returns the following results in a SPILL range.

FILTER results showing employee names, two unwanted date serial columns and positions

The unwanted side-effect of this result is we are including the Start Date and Birth Date columns in our filtered result.

Unwanted date columns highlighted in the Excel FILTER results

The results aren’t formatted as dates, so they look a bit strange; but trust me, they are dates.  These are the number-equivalent versions of dates.

The next step is to remove the unwanted columns from the result.

Return Non-Adjacent Columns with a Second FILTER

To remove the unwanted date columns, wrap the first FILTER inside a second FILTER. We’ll use 1 to keep a column and 0 to leave it out.

We start by updating the formula by placing the entire existing FILTER formula within another FILTER function.  The original FILTER function will be the Array argument of the additional FILTER function.

=FILTER(FILTER(TSal[[Name]:[Position]], Tsal[Salary] > J2),

The Include argument will use array syntax to select the 1st and 4th columns, in their entirety, from the original FILTER results.

=FILTER(FILTER(TSal[[Name]:[Position]], Tsal[Salary] > J2), {1, 0, 0, 1})

How the 1/0 Column Flags Work

In Excel, 1 is treated as TRUE while 0 (zero) is treated as FALSE.

Excel will apply a 1 (TRUE) to every item in the 1st column of the Array argument, a 0 (False) to every item in the 2nd and 3rd columns, and a 1 to every item in the 4th column.

This 1/0 pattern lets FILTER return columns 1 and 4 while excluding columns 2 and 3.

The results are as follows.

Nested FILTER formula returning only employee names and positions above the salary threshold

Sort Results by Name or Position

As an extra touch, we can sort the results by Name in ascending order by wrapping the FILTER/FILTER formula in a SORT function.

=SORT(FILTER(FILTER(TSal[[Name]:[Position]], Tsal[Salary] > J2), {1, 0, 0, 1}) )
SORT function ordering matching employee names alphabetically

Add 2 as the sort_index argument to sort by the second column, Position, instead of Name.

=SORT(FILTER(FILTER(TSal[[Name]:[Position]], Tsal[Salary] > J2), {1, 0, 0, 1}), 2)
Excel SORT formula ordering the filtered employee results by position

Get Unique Department and Position Combinations

Suppose we want a list of every distinct Department and Position combination. UNIQUE can remove duplicate combinations after FILTER selects those two columns.

We can integrate the UNIQUE function while at the same time using the 1/0 trick to produce the result.

  1. We only need Department (column A) and Position (column E). Start with the five-column range from Department through Position, then keep the first and fifth columns.
=FILTER(TSal[[Department]:[Position]],
  1. We’ll use the 1/0 trick to remove the unwanted columns.
=FILTER(TSal[[Department]:[Position]], {1, 0, 0, 0, 1})
  1. Next, we’ll reduce the list to only one of each Department/Position combination; in other words, remove the duplicates.
=UNIQUE(FILTER(TSal[[Department]:[Position]], {1, 0, 0, 0, 1}) )
  1. Lastly, we’ll sort the list in ascending order by Department.
=SORT(UNIQUE(FILTER(TSal[[Department]:[Position]], {1, 0, 0, 0, 1}) ) )

If you wanted to perform a primary sort by Department and a secondary sort by Position, you could add instructions to the [sort_index] argument to sort by the 1st column, then by the 2nd column.

=SORT(UNIQUE(FILTER(TSal[[Department]:[Position]], {1, 0, 0, 0, 1}) ), {1, 2} )
SORT UNIQUE and FILTER formula returning distinct department and position combinations

For more examples of dynamic arrays, see our guide to SORT, UNIQUE, FILTER and other modern Excel functions.

A Shorter Option with CHOOSECOLS

The nested FILTER method works in Excel 2021, but there’s a shorter option if you use Microsoft 365 or Excel 2024.

CHOOSECOLS lets you select specific columns from an array by number. That means you can filter the employee records and return only Name and Position without needing a second FILTER.

In our Name-to-Position range, Name is the first column and Position is the fourth:


=CHOOSECOLS(FILTER(TSal[[Name]:[Position]],TSal[Salary]>J2),1,4)

For the unique Department and Position list, select columns 1 and 5 first, then use UNIQUE and SORT:


=SORT(UNIQUE(CHOOSECOLS(TSal[[Department]:[Position]],1,5)),{1,2})

You can also sort by Salary without showing it. Sort the five-column result first, then use CHOOSECOLS to keep only Name and Position:


=CHOOSECOLS(SORT(FILTER(TSal[[Name]:[Salary]],TSal[Salary]>J2),5,-1),1,4)

Both methods return dynamic results. Use the original nested FILTER technique if you’re working in Excel 2021. If you have CHOOSECOLS, the formulas are easier to read.

Want to filter by more than one condition? See how to use FILTER with AND and OR criteria.

Test That the Results Update Automatically

To ensure our result will operate properly under real-world conditions, perform the following tests:

  • Change the earnings threshold (cell J2) to different values and see if the Name/Position table updates.
  • Add new records to the table and see if those new records appear in the Name/Position table (assuming they have salaries over the value defined in cell J2).
  • Change an existing department or position, or add a new combination. Check that the unique Department and Position list updates automatically.

Sort by Salary Without Showing the Salary Column

Returning to the list of Names and Positions we generated earlier; suppose we wanted to sort the list in descending order by Salary.

Since there’s no Salary information in the result, this seems like an impossible task.

A very clever trick is to rearrange the nesting order of the functions to apply actions in a different sequence.

Take, for example, the following updated formula:

=FILTER(SORT(FILTER(TSal[[Name]:[Salary]], TSal[Salary] > J2), 5, -1), {1, 0, 0, 1, 0})

How the Salary Sort Formula Works

We begin by selecting the columns of data from Name to Salary.

=FILTER(TSal[[Name]:[Salary]],

Next, we filter the rows to only include those with salaries greater than the value defined in cell J2.

=FILTER(TSal[[Name]:[Salary]], TSal[Salary] > J2)

Next, sort the filtered result by Salary, which is the fifth column in the selected range. Use -1 for descending order.

=SORT(FILTER(TSal[[Name]:[Salary]], TSal[Salary] > J2), 5, -1)

With the newly sorted table, we use our previously discovered 1/0 trick to keep the 1st and 4th columns (Name & Position) while filtering out the remaining columns.

=FILTER(SORT(FILTER(TSal[[Name]:[Salary]], TSal[Salary] > J2), 5, -1), {1, 0, 0, 1, 0})
Filtered employee names and positions sorted by salary descending without displaying salaries

Download the FILTER Practice Workbook

Download the FILTER Practice Workbook

Try the non-adjacent column formulas from this tutorial in Excel.

Frequently Asked Questions

Can FILTER return non-adjacent columns in Excel?

Yes. Apply FILTER once to select matching rows and a second time to select columns. The horizontal array {1,0,0,1} keeps Name and Position from the four-column Name-to-Position range while leaving out Start Date and Birth Date.

What do 1 and 0 mean in a FILTER formula?

In the horizontal include array, 1 means TRUE and keeps the corresponding column, while 0 means FALSE and excludes it. The number of flags must match the number of columns in the filtered array.

Can CHOOSECOLS replace a second FILTER?

Yes. In Microsoft 365 or Excel 2024, CHOOSECOLS selects columns by position from the result of FILTER. Excel 2021 supports FILTER but does not include CHOOSECOLS.

How do I sort by Salary without showing the Salary column?

Filter the range from Name through Salary, use SORT on the fifth column in descending order, then keep only Name and Position. Sorting before removing Salary preserves the sort key.

How do I return unique combinations from non-adjacent columns?

Select Department and Position with a second FILTER or CHOOSECOLS, wrap that result in UNIQUE, and then use SORT. UNIQUE removes duplicate Department and Position combinations rather than removing every repeated department or position.

Why does FILTER return #CALC! when no rows match?

If FILTER finds no matching rows and no alternative result is supplied, it can return #CALC!. For nested FILTER formulas, wrap the complete expression in IFERROR to show a message. IFERROR also hides unrelated errors, so use it carefully.

Leila Gharani

Founder of XelPlus and ten-time Microsoft MVP. Leila helps over 500,000 professionals master Excel, Power BI, and data automation through practical, real-world training.