Search code examples
google-sheetsgoogle-sheets-formula

How can I get all the unique pairs of values from two columns across tabs in Google Spreadsheet?


Say that I have in tab 1:

|Column A | Column B |
| ------- | -------- |
|Apple    | Fruit    |
|Banana   | Fruit    |
|Celery   | Vegetable|
|Tomato   | Fruit    |
|Tomato   | Vegetable|
|Avocado  | Fruit    |

And in tab 2:

|Column A | Column B |
| ------- | -------- |
|Apple    | Fruit    |
|Banana   | Fruit    |
|Carrot   | Vegetable|
|Tomato   | Vegetable|
|Avocado  | Vegetable|
|Carrot   | Root     |

I now want in tab 3, in column A and B, all unique pairs of columns A and B from tab 1 and 2, so that the result would be:

|Column A | Column B |
| ------- | -------- |
|Banana   | Fruit    | 
|Celery   | Vegetable|
|Carrot   | Vegetable|
|Carrot   | Root     |
|Tomato   | Fruit    |
|Tomato   | Vegetable|
|Avocado  | Fruit    |
|Avocado  | Vegetable|

I've tried the CHOOSECOLS function in combination with UNIQUE but that didn't give me all combinations. I can't concatenate because I want the result in tab 3 to be in two columns. I can't use powerquery either because I don't have access to it


Solution

  • You can use the UNIQUE function:

    =QUERY(UNIQUE({Sheet1!A2:B;Sheet2!A2:B}),"where Col1 is not null")