Search code examples
google-sheets-formulaxlookup

XLOOKUP in Google Sheets works only on the first line with the searched value


I've got a problem with populating whole table in Google sheets. I want to pull out all the data rows based on one product name from A2 cell.

I've created such formula, which taking the data from another sheet and give us searched details. From such base I want to look up all the details enter image description here

Formula I used in B5 cell is enter image description here

=xlookup($A$2,IMPORTRANGE("https://docs.google.com/spreadsheets/d/1O1AF3JewmhEoly_dhFWbkax-T5Q7oeQKYjia-Ci1vd0/edit#gid=201","SKUDatabase!B:B"),IMPORTRANGE("https://docs.google.com/spreadsheets/d/1O1AF3JewmhEoly_dhFWbkax-T5Q7oeQKYjia-Ci1vd0/edit#gid=201","SKUDatabase!A:A"))

Although the xlookup perefctly pulls out the data for the first row it can't look up for the new next data row of the same product (Sausage in this case). As I drag the formula down, only what is done is copying the same data, not adding the new rows with different product details. enter image description here

Could you please help how to remake the formula as it can pull out all of the details based on one cell with product name?


Solution

  • To achieve your desired result of pulling out all the details based on one cell with the product name, you can use the FILTER function along with IMPORTRANGE. The FILTER function will allow you to filter the rows based on the product name, and IMPORTRANGE will fetch the data from the other sheet. Here's the formula you can use in cell B5:

    =FILTER(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1O1AF3JewmhEoly_dhFWbkax-T5Q7oeQKYjia-Ci1vd0/edit#gid=201", "SKUDatabase!A2:C"), IMPORTRANGE("https://docs.google.com/spreadsheets/d/1O1AF3JewmhEoly_dhFWbkax-T5Q7oeQKYjia-Ci1vd0/edit#gid=201", "SKUDatabase!A2:A") = $A$2)
    

    This formula will pull out all the rows from columns A, B, and C in the "SKUDatabase" sheet where the product name in column A matches the value in cell A2. Make sure to replace the URL with the correct URL of your Google Sheets document. Also, make sure that the IMPORTRANGE function has permission to access the data from the other sheet. When you drag the formula down, it will populate the rows with different product details that match the product name in cell A2.