Bottom Line: Learn how to create a formula that returns unique combinations of values from non-adjacent columns.
Skill Level: Intermediate
Watch the Tutorial
Download the Excel File
If you want to follow along, you can use this workbook. It's the same file I use in the video.
Pulling Unique Lists from Columns That Aren't Adjacent
We received a great question from Irene, who is an Elevate Excel member. She's curious to know if the UNIQUE function can be used to pull entries from columns that are not side by side or next to each other.
The answer to Irene's question is: on it's own, the UNIQUE function can only find unique combinations from adjacent columns. However, we can write a formula to work around that. This formula will essentially create an array of the non-adjacent columns that you want to reference in the UNIQUE function.
It's a similar process to what I explained in this tutorial on the FILTER Formula to Return Non-Adjacent Columns in Any Order.
Here's how to write the formula we need:
Use INDEX to Create an Array for Non-Adjacent Columns
Below is an example where we want to use the UNIQUE function, which is a dynamic array function, to return a list of unique combinations of Customer Names and Product Names. As you can see, those two columns are not next to each other.
Since the UNIQUE function does not handle that on its own, we have to use use another formula to help. So we're going to use INDEX.
For the INDEX function, the first argument is the array. We will select the entire table for the array.
The next argument is row number (row_num). To define the row numbers we want, we'll first create a list of row numbers using the SEQUENCE function.
The first argument (and the only one we need) in SEQUENCE is rows. To define rows, we will actually use the ROWS function. The only argument for the ROWS function is array, and for that, we will again reference the entire table. This will return every row from the table to our new array.
To define the column number argument (column_num), we can reference column numbers as an array in curly brackets. In our case we want to pull from columns 1 and 3. Those column numbers are specific to the table we're working with, not the sheet overall.
So, all together, our formula to return an array of non-adjacent columns looks like this:
Wrap the Formula with UNIQUE
Now that we've created a spill range that shows the columns we want, we simply have to wrap our existing formula with the UNIQUE function.
The UNIQUE function has other arguments, but the only one we need to use is array. Our array is defined by the formula we already created. So the final formula looks like this:
With our duplicates filtered out, our spill range only shows unique entries from the two columns we wanted to pull from.
You can then sort the list of unique values by wrapping the formula in the SORT or SORBY function. Or you could further filter down the results with the FILTER function.
The possibilities are endless in terms of what you can do with dynamic arrays to create flexible, interactive reports. Checkout our video & post on Dynamic Array Formulas & Spill Ranges to learn more.
Please leave a comment below with any questions or suggestions. Until next time!